On Sun, Jul 26, 2009 at 17:59, John W. Krahn<jwkr...@shaw.ca> wrote:
> Bryan Harris wrote:
snip
>> Oddly, perl won't let me do "my ($_) = shift;", so I'm stuck having to use
>> another variable.
>
> Perl 5.10 *will* let you do "my $_".
snip

Be warned that you may reveal bugs if you use make $_ lexical:

#!/usr/bin/perl

use 5.010;
use strict;
use warnings;

use List::Util qw/first/;

my $first = (first { $_ eq "f" } "a" .. "z") // "undef";

say "with global \$_: $first";

{
        my $_ = "foo";
        my $first = (first { $_ eq "f" } "a" .. "z") // "undef";

        say "with lexical \$_: $first";
}

my $first = (first { $_ eq "f" } "a" .. "z") // "undef";

say "still fine with global \$_: $first";

{
        local $_ = "foo";

        my $first = (first { $_ eq "f" } "a" .. "z") // "undef";

        say "still fine with local \$_: $first";
}

This bug is currently being discussed on the Perl 5 Porters list and
may be fixed in 5.10.1.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to