in reply to Are we seeing syntax inconsistency?

The warning is coming from the sub { print $_ }. Because that's an anonymous subroutine, its evaluation will be deferred until later. You don't know if something else hasn't trounced on the value of $_ by the time it's evaluated.

The following code will issue the same warning.

#!/usr/bin/perl use strict; use warnings; sub foo { my $sub = shift; local $_; $sub->(); } $_ = 10; foo (sub { print $_ });

The values of the variables in the anonymous subroutine are not evaluated until the subroutine is executed. Otherwise, our lexical closures wouldn't work. You are very unlikely to see that with properly scoped lexical variables, but here's how you can make it happen:

#!/usr/bin/perl use strict; use warnings; my $var = 10; foo(sub { print $var }); sub foo { my $sub = shift; undef $var; $sub->(); # unitialized warning }

Cheers,
Ovid

New address of my CGI Course.