1N/A#!./perl
1N/A
1N/A# $RCSfile: my.t,v $
1N/A
1N/Aprint "1..33\n";
1N/A
1N/Asub foo {
1N/A my($a, $b) = @_;
1N/A my $c;
1N/A my $d;
1N/A $c = "ok 3\n";
1N/A $d = "ok 4\n";
1N/A { my($a, undef, $c) = ("ok 9\n", "not ok 10\n", "ok 10\n");
1N/A ($x, $y) = ($a, $c); }
1N/A print $a, $b;
1N/A $c . $d;
1N/A}
1N/A
1N/A$a = "ok 5\n";
1N/A$b = "ok 6\n";
1N/A$c = "ok 7\n";
1N/A$d = "ok 8\n";
1N/A
1N/Aprint &foo("ok 1\n","ok 2\n");
1N/A
1N/Aprint $a,$b,$c,$d,$x,$y;
1N/A
1N/A# same thing, only with arrays and associative arrays
1N/A
1N/Asub foo2 {
1N/A my($a, @b) = @_;
1N/A my(@c, %d);
1N/A @c = "ok 13\n";
1N/A $d{''} = "ok 14\n";
1N/A { my($a,@c) = ("ok 19\n", "ok 20\n"); ($x, $y) = ($a, @c); }
1N/A print $a, @b;
1N/A $c[0] . $d{''};
1N/A}
1N/A
1N/A$a = "ok 15\n";
1N/A@b = "ok 16\n";
1N/A@c = "ok 17\n";
1N/A$d{''} = "ok 18\n";
1N/A
1N/Aprint &foo2("ok 11\n","ok 12\n");
1N/A
1N/Aprint $a,@b,@c,%d,$x,$y;
1N/A
1N/Amy $i = "outer";
1N/A
1N/Aif (my $i = "inner") {
1N/A print "not " if $i ne "inner";
1N/A}
1N/Aprint "ok 21\n";
1N/A
1N/Aif ((my $i = 1) == 0) {
1N/A print "not ";
1N/A}
1N/Aelse {
1N/A print "not" if $i != 1;
1N/A}
1N/Aprint "ok 22\n";
1N/A
1N/Amy $j = 5;
1N/Awhile (my $i = --$j) {
1N/A print("not "), last unless $i > 0;
1N/A}
1N/Acontinue {
1N/A print("not "), last unless $i > 0;
1N/A}
1N/Aprint "ok 23\n";
1N/A
1N/A$j = 5;
1N/Afor (my $i = 0; (my $k = $i) < $j; ++$i) {
1N/A print("not "), last unless $i >= 0 && $i < $j && $i == $k;
1N/A}
1N/Aprint "ok 24\n";
1N/Aprint "not " if defined $k;
1N/Aprint "ok 25\n";
1N/A
1N/Aforeach my $i (26, 27) {
1N/A print "ok $i\n";
1N/A}
1N/A
1N/Aprint "not " if $i ne "outer";
1N/Aprint "ok 28\n";
1N/A
1N/A# Ensure that C<my @y> (without parens) doesn't force scalar context.
1N/Amy @x;
1N/A{ @x = my @y }
1N/Aprint +(@x ? "not " : ""), "ok 29\n";
1N/A{ @x = my %y }
1N/Aprint +(@x ? "not " : ""), "ok 30\n";
1N/A
1N/A# Found in HTML::FormatPS
1N/Amy %fonts = qw(nok 31);
1N/Afor my $full (keys %fonts) {
1N/A $full =~ s/^n//;
1N/A # Supposed to be copy-on-write via force_normal after a THINKFIRST check.
1N/A print "$full $fonts{nok}\n";
1N/A}
1N/A
1N/A# [perl #29340] optimising away the = () left the padav returning the
1N/A# array rather than the contents, leading to 'Bizarre copy of array' error
1N/A
1N/Asub opta { my @a=() }
1N/Asub opth { my %h=() }
1N/Aeval { my $x = opta };
1N/Aprint "not " if $@;
1N/Aprint "ok 32\n";
1N/Aeval { my $x = opth };
1N/Aprint "not " if $@;
1N/Aprint "ok 33\n";