@INC = '../lib';
}
-print "1..48\n";
+print "1..66\n";
my $test = 0;
sub ok ($$) {
$_ = "global";
{
+ my $_ = 'local';
for my $_ ("foo") {
ok( $_ eq "foo", 'for my $_' );
/(.)/;
ok( $1 eq "f", '...m// in for my $_' );
ok( our $_ eq 'global', '...our $_ inside for my $_' );
}
- ok( $_ eq 'global', '...$_ restored outside for my $_' );
+ ok( $_ eq 'local', '...my $_ restored outside for my $_' );
+ ok( our $_ eq 'global', '...our $_ restored outside for my $_' );
+}
+{
+ my $_ = 'local';
+ for ("implicit foo") { # implicit "my $_"
+ ok( $_ eq "implicit foo", 'for implicit my $_' );
+ /(.)/;
+ ok( $1 eq "i", '...m// in for implicity my $_' );
+ ok( our $_ eq 'global', '...our $_ inside for implicit my $_' );
+ }
+ ok( $_ eq 'local', '...my $_ restored outside for implicit my $_' );
+ ok( our $_ eq 'global', '...our $_ restored outside for implicit my $_' );
+}
+{
+ my $_ = 'local';
+ ok( $_ eq "postfix foo", 'postfix for' ) for 'postfix foo';
+ ok( $_ eq 'local', '...my $_ restored outside postfix for' );
+ ok( our $_ eq 'global', '...our $_ restored outside postfix for' );
}
{
for our $_ ("bar") {
ok( /^[67]\z/, 'local lexical $_ is seen in map' );
{ ok( our $_ eq 'global', 'our $_ still visible' ); }
ok( $_ == 6 || $_ == 7, 'local lexical $_ is still seen in map' );
+ { my $_ ; ok( !defined, 'nested my $_ is undefined' ); }
} 6, 7;
ok( $buf eq 'gxgx', q/...map doesn't modify outer lexical $_/ );
ok( $_ eq 'x', '...my $_ restored outside map' );
ok( our $_ eq 'global', '...our $_ restored outside map' );
+ map { my $_; ok( !defined, 'redeclaring $_ in map block undefs it' ); } 1;
+}
+{ map { my $_; ok( !defined, 'declaring $_ in map block undefs it' ); } 1; }
+{
+ sub tmap3 () { return $_ };
+ my $_ = 'local';
+ sub tmap4 () { return $_ };
+ my $x = join '-', map $_.tmap3.tmap4, 1 .. 2;
+ ok( $x eq '1globallocal-2globallocal', 'map without {}' );
+}
+{
+ for my $_ (1) {
+ my $x = map $_, qw(a b);
+ ok( $x == 2, 'map in scalar context' );
+ }
}
{
my $buf = '';
ok( our $_ eq 'global', '...our $_ restored outside grep' );
}
{
+ sub tgrep3 () { return $_ };
+ my $_ = 'local';
+ sub tgrep4 () { return $_ };
+ my $x = join '-', grep $_=$_.tgrep3.tgrep4, 1 .. 2;
+ ok( $x eq '1globallocal-2globallocal', 'grep without {} with side-effect' );
+ ok( $_ eq 'local', '...but without extraneous side-effects' );
+}
+{
+ for my $_ (1) {
+ my $x = grep $_, qw(a b);
+ ok( $x == 2, 'grep in scalar context' );
+ }
+}
+{
my $s = "toto";
my $_ = "titi";
$s =~ /to(?{ ok( $_ eq 'toto', 'my $_ in code-match # TODO' ) })to/
{
my $_ = "abc";
my $x = reverse;
- ok( $x eq "cba", 'reverse without arguments picks up $_ # TODO' );
+ ok( $x eq "cba", 'reverse without arguments picks up $_' );
}
{