-#!./perl -w
+#!./perl
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
}
-print "1..56\n";
+print "1..70\n";
my $test = 0;
sub ok ($$) {
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( $_ eq "bar", 'for our $_' );
/(.)/;
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 = '';
sub tgrep1 { /(.)/; $buf .= $1 }
my $_ = 'y';
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 $_' );
}
{
ok( $x eq "hello\n", 'reading from <$_> works' );
close $_;
}
+
+{
+ $fqdb::_ = 'fqdb';
+ ok( $fqdb::_ eq 'fqdb', 'fully qualified $_ is not in main' );
+ ok( eval q/$fqdb::_/ eq 'fqdb', 'fully qualified, evaled $_ is not in main' );
+ package fqdb;
+ ::ok( $_ ne 'fqdb', 'unqualified $_ is in main' );
+ ::ok( q/$_/ ne 'fqdb', 'unqualified, evaled $_ is in main' );
+}