> > ----------------------------------------------------------------- > [Please enter your report here] > > Please behold the following: [code snipped] > Note that when commenting out the lexical declaration of $_, the code behaves > as expected. No it doesn't. Or at least not for me. I suggest you check your test case again. This seem to happen because given creates a lexical $_. It also happens when for/foreach is used with a lexical $_: #!/usr/bin/perl -l use strict; use warnings; use feature qw/switch/; sub s1 (&) { my $code = shift; for ("a") { print "\ts1:\t \$_ = " . \$_ . " (value: $_)"; $code->(); } } print "Given/when block:"; my $val = 1; given ($val) { when (1) { print "\twhen-1:\t \$_ = " . \$_ . " (value: $_)"; s1 { print "\tblock:\t \$_ = " . \$_ . " (value: $_)"; }; print "\twhen-2:\t \$_ = " . \$_ . " (value: $_)"; } } print ""; print "For loop"; for (1) { print "\tfor-1:\t \$_ = " . \$_ . " (value: $_)"; s1 { print "\tblock:\t \$_ = " . \$_ . " (value: $_)"; }; print "\tfor-2:\t \$_ = " . \$_ . " (value: $_)"; } print ""; print "For loop with lexical \$_"; for my $_ (1) { print "\tfor-1:\t \$_ = " . \$_ . " (value: $_)"; s1 { print "\tblock:\t \$_ = " . \$_ . " (value: $_)"; }; print "\tfor-2:\t \$_ = " . \$_ . " (value: $_)"; } __END__ $ perl-5.10.0 rt-67694.pl Given/when block: when-1: $_ = SCALAR(0x994f768) (value: 1) s1: $_ = SCALAR(0x994f478) (value: a) block: $_ = SCALAR(0x994f768) (value: 1) when-2: $_ = SCALAR(0x994f768) (value: 1) For loop for-1: $_ = SCALAR(0x994ed08) (value: 1) s1: $_ = SCALAR(0x994f478) (value: a) block: $_ = SCALAR(0x994f478) (value: a) for-2: $_ = SCALAR(0x994ed08) (value: 1) For loop with lexical $_ for-1: $_ = SCALAR(0x994e848) (value: 1) s1: $_ = SCALAR(0x994f478) (value: a) block: $_ = SCALAR(0x994e848) (value: 1) for-2: $_ = SCALAR(0x994e848) (value: 1) Best regards, BramThread Previous | Thread Next