http://www.perlmonks.org?node_id=933579

mbethke has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys,

I just noticed that the given/when construct's way of introducing a lexical $_ plays badly with functions that take BLOCKs such as List::MoreUtils::any. The following does not print anything:

use 5.010; use strict; use warnings; use List::MoreUtils qw/ any /; my $s = "foo"; my @list = ( 1, undef, 2 ); given($s) { when('foo') { say "found undef" if any { ! defined($_) } @list; } }

Within the block, $_ is always 'foo' as it was bound during the block's definition.

Now this must be a known problem, right? For my inner peace, could someone explain me the rationale for making "given" so subtly different from say "for"? And for my productivity, is there a way around it short of "don't use 'given'"?

Thanks very much!