11 sub f($$_) { my $x = shift; is("@_", $x) }
17 f("FOO xy", $foo, "xy");
18 f("BAR zt", $bar, "zt");
21 f("y 42", substr("xy",1,1));
22 f("1 42", ("abcdef" =~ /abc/));
23 f("not undef 42", $undef || "not undef");
24 f(" 42", -f "no_such_file");
25 f("FOOBAR 42", ($foo . $bar));
26 f("FOOBAR 42", ($foo .= $bar));
30 like( $@, qr/Not enough arguments for main::f at/ );
32 like( $@, qr/Too many arguments for main::f at/ );
35 my $_ = "quarante-deux";
38 f("FOO quarante-deux", $foo);
39 f("BAR quarante-deux", $bar);
40 f("y quarante-deux", substr("xy",1,1));
41 f("1 quarante-deux", ("abcdef" =~ /abc/));
42 f("not undef quarante-deux", $undef || "not undef");
43 f(" quarante-deux", -f "no_such_file");
44 f("FOOBAR quarante-deux", ($foo . $bar));
45 f("FOOBAR quarante-deux", ($foo .= $bar));
46 f("FOOBAR quarante-deux", $foo);
51 sub g(_) { is(shift, $expected) }
59 undef $expected; &g; # $_ not passed
60 { $expected = my $_ = "bar"; g() }
62 eval q{ sub wrong1 (_$); wrong1(1,2) };
63 like( $@, qr/Malformed prototype for main::wrong1/, 'wrong1' );
65 eval q{ sub wrong2 ($__); wrong2(1,2) };
66 like( $@, qr/Malformed prototype for main::wrong2/, 'wrong2' );
68 sub opt ($;_) { is($_[0], "seen"); ok(!defined $_[1], "; has precedence over _") }
71 sub unop (_) { is($_[0], 11, "unary op") }
72 unop 11, 22; # takes only the first parameter into account
74 sub mymkdir (_;$) { is("@_", $expected, "mymkdir") }
75 $expected = $_ = "mydir"; mymkdir();
76 mymkdir($expected = "foo");
77 $expected = "foo 493"; mymkdir foo => 0755;
79 # $_ says modifiable, it's not passed by copy
81 sub double(_) { $_[0] *= 2 }
84 is( $_, 42, '$_ is modifiable' );
88 is( $_, 44, 'my $_ is modifiable' );