note
hipowls
<p>Really, I too was surprised. Changing sub test to
<code>
sub test {
my @rv = $_[0] =~ /^([0-9]+)$/;
print "<<@rv>>\n";
return @rv[ 0 .. $#rv ];
}
</code>
produced
<code>
<<>>
[[]
<<>>
[]
<<123>>
[123]
<<123>>
[123]
</code>
changing sub test to
<code>
sub test {
my @rv = $_[0] =~ /^([0-9]+)$/;
print "<<@rv>>\n";
return wantarray? @rv: $rv[-1];
}
</code>
produces
<code>
michael$ perl t.pl
<<>>
Use of uninitialized value in print at t.pl line 5.
[]
<<>>
[]
<<123>>
[123]
<<123>>
[123]
</code>
Note the warning. (And I suspect there are some monks who are now saying I told you so;-)</p>
663945
663966