Look at the following code fragment and try and guess what the output will be:
use strict;
my $foo = "Hello World!";
_Printer(0, 1, 2, 3, ($foo =~ m/zoom/), 5);
sub _Printer
{
my $foo;
my $i = 0;
while (scalar(@_)) {
$foo = shift;
print "$i: $foo\n";
$i++;
}
}
If you thought the output should look like the following, you're wrong:
0: 0
1: 1
2: 2
3: 3
4:
5: 5
The actual output (on my 5.6 Linux version of perl) is the following:
0: 0
1: 1
2: 2
3: 3
4: 5
Apparently, Perl doesn't pass in a false or undef value for a failed regular expression match; instead,
it completely ignores the argument. A passing
regex match
does get passed in, with a value of 1.
Anybody want to take a shot at explaining this?
-Ton
-----
Be bloody, bold, and resolute; laugh to scorn
The power of man...