On Mon, Jun 13, 2005 at 12:47:40PM -0400, Sean Quinlan wrote:

>         my $out = _stop(\$seq1,$pos,$minlen,$id) if $seq1 =~ /\.$/;

my has both compile-time behavior and run-time behavior.  At compile-time,
my allocates the memory for the variable.  At run-time, my (re)initializes
the variable.  With the construct C<my $var = EXPR if CONDITION>, if the
condition is false, the assignment will not occur, as expected, but in
addition, the variable will not be reinitialized, so it will keep whatever
value it had the last time the block was executed.

This is an unintentional feature (aka bug), but it has been preserved for
backwards compatibility; some people have found it useful for creating
closures.

You already found the appropriate fix, which is not to put a statement
modifier on a my statement.

Ronald

 
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to