14 print $ok ? "ok $test - $name\n" : "not ok $test - $name\n";
18 ok( $_ eq 'global', '$_ initial value' );
20 ok( $_ eq 'glabol', 's/// on global $_' );
24 ok( $_ eq 'local', 'my $_ initial value' );
26 ok( $_ eq 'lacol', 's/// on my $_' );
28 ok( $1 eq 'la', '// on my $_' );
29 ok( tr/c/d/ == 1, 'tr/// on my $_ counts correctly' );
30 ok( $_ eq 'ladol', 'tr/// on my $_' );
33 ok( $_ eq 'nested', 'my $_ nested' );
35 ok( $_ eq 'neste', 'chop on my $_' );
39 ok( $_ eq 'glabol', 'gains access to our global $_' );
41 ok( $_ eq 'ladol', 'my $_ restored' );
43 ok( $_ eq 'glabol', 'global $_ restored' );
45 ok( $_ eq 'global', 's/// on global $_ again' );
49 ok( $_ eq 22, 'our $_ is seen explicitly' );
51 ok( $_ eq 2, '...default chop chops our $_' );
53 ok( $1 eq 2, '...default match sees our $_' );
59 ok( $_ eq "foo", 'for my $_' );
61 ok( $1 eq "f", '...m// in for my $_' );
62 ok( our $_ eq 'global', '...our $_ inside for my $_' );
64 ok( $_ eq 'global', '...$_ restored outside for my $_' );
68 ok( $_ eq "bar", 'for our $_' );
70 ok( $1 eq "b", '...m// in for our $_' );
72 ok( $_ eq 'global', '...our $_ restored outside for our $_' );
77 sub tmap1 { /(.)/; $buf .= $1 } # uses our $_
79 sub tmap2 { /(.)/; $buf .= $1 } # uses my $_
83 ok( /^[67]\z/, 'local lexical $_ is seen in map' );
84 { ok( our $_ eq 'global', 'our $_ still visible' ); }
85 ok( $_ == 6 || $_ == 7, 'local lexical $_ is still seen in map' );
87 ok( $buf eq 'gxgx', q/...map doesn't modify outer lexical $_/ );
88 ok( $_ eq 'x', '...my $_ restored outside map' );
89 ok( our $_ eq 'global', '...our $_ restored outside map' );
93 sub tgrep1 { /(.)/; $buf .= $1 }
95 sub tgrep2 { /(.)/; $buf .= $1 }
99 ok( /^[89]\z/, 'local lexical $_ is seen in grep' );
100 { ok( our $_ eq 'global', 'our $_ still visible' ); }
101 ok( $_ == 8 || $_ == 9, 'local lexical $_ is still seen in grep' );
103 ok( $buf eq 'gygy', q/...grep doesn't modify outer lexical $_/ );
104 ok( $_ eq 'y', '...my $_ restored outside grep' );
105 ok( our $_ eq 'global', '...our $_ restored outside grep' );
110 $s =~ /to(?{ ok( $_ eq 'toto', 'my $_ in code-match # TODO' ) })to/
111 or ok( 0, "\$s=$s should match!" );
112 ok( our $_ eq 'global', '...our $_ restored outside code-match' );
118 ok( $x eq "cba", 'reverse without arguments picks up $_ # TODO' );
124 ::ok( $::_ eq 'notmain', 'our $_ forced into main::' );
126 ::ok( $1 eq 'notmain', '...m// defaults to our $_ in main::' );
129 my $file = 'dolbar1.tmp';
130 END { unlink $file; }
132 open my $_, '>', $file or die "Can't open $file: $!";
135 ok( -s $file, 'writing to filehandle $_ works' );
138 open my $_, $file or die "Can't open $file: $!";
140 ok( $x eq "hello\n", 'reading from <$_> works' );