>>>>> "SQ" == Sean Quinlan <[EMAIL PROTECTED]> writes:
SQ> Where the 'SixFrame' line is the content of $out. There doesn't seem to
SQ> be any obvious pattern to how many times the output would be repeated,
SQ> but I didn't bother to investigate that deeply. Changing the "my $out =
SQ> _stop" line in the while loop above to:
SQ> my $out = '';
SQ> $out .= _stop(\$seq1,$pos,$minlen,$id) if $seq1 =~ /\.$/;
you have run into a classic issue (but not a bug) with my and
conditional modifiers.
my is both a compile time directive (declaring a lexical variable) and a
run time operation (usually assigning undef to the variable). but you do
the equivilent of
my $x = 3 if 0 ;
so the code declares $x but doesn't assign 3 since the conditional
fails. as an undocumented side effect, $x will not be assigned 3 if it
is executed again in a loop or even recalling the sub it is in. it
becomes a static var inside the sub. you can modify and access it later
and it will keep its value between calls. as i said, this is an
accidental undocumented feature that is really a bug (it shouldn't be
allowed).
so your $out is staying around between calls and that causes your wierd
output. declaring it on its own line will cause it to be properly
initialized each time through the sub or loop which is what you
want. and it is better code as well even if it did work the way you
expected it to.
SQ> Seems to have completely solved the problem. Is this some sort of
SQ> mistake on my part, some subtle/odd behavior that would cause this to be
SQ> expected in this usage (and if so please explain), or should I report
SQ> this as a bug [no, I haven't trolled the known bugs/fixes yet, sorry]
this has been discussed on many forums before. the rule is never to do
anything on a my declaration other than to initialize it. statement
modifiers on them are very bad things (and as i said, should be
illegal).
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm