perlsyn lies when it says:
C<when> executes the statement I<when> C<$_> smart matches C<EXPR>, and
then either C<break>s out if it's enclosed in a C<given> scope or skips
to the C<next> element when it lies directly inside a C<for> loop.
That's not true. This works perfectly well:
use 5.010;
@names = qw(Peter Bob Jim David Stark);
for (@names) {
func();
}
sub func {
say "$_ is Alice or Bob" when [ qw/Alice Bob/ ];
say "$_ is Chris, David, or Ellen" when [ qw/Chris David Ellen/ ];
default { say "Who is $_?" }
}
It at some later point suggests:
This doesn't work if you explicitly specify a loop variable,
as in C<for $item (@array)>. You have to use the default
variable C<$_>. (You can use C<for my $_ (@array)>.)
Well *DUH* if you're foolish enough to use a stupid lexical $_,
then of course stuff doesn't work! Don't do that. The correct
construct is the one I use above, not the dumb one that's
misrecommended.
Later it reads:
when($foo)
is exactly equivalent to
when($_ ~~ $foo)
And then it goes on to list a whole bunch of exclusions.
Therefore, it is lying. It is *NOT* exactly equivalent to that.
We should be so lucky.
And its list of exclusions is not definitive. There is no
way to figure out what the bloody thing does without testing it
yourself. The documentation is misleading and wrong, unhelpful
and ambiguous.
It should be removed.
And it's been what, almost four years that people have put up
with this?
Unbelievable.
--tom
Thread Next