ton has asked for the wisdom of the Perl Monks concerning the following question:
If you thought the output should look like the following, you're wrong: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++; } }
The actual output (on my 5.6 Linux version of perl) is the following:0: 0 1: 1 2: 2 3: 3 4: 5: 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.0: 0 1: 1 2: 2 3: 3 4: 5
Anybody want to take a shot at explaining this?
-Ton
-----
Be bloody, bold, and resolute; laugh to scorn
The power of man...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing match regexs as arguments to subroutines
by japhy (Canon) on Jul 24, 2001 at 06:15 UTC | |
by ton (Friar) on Jul 24, 2001 at 06:57 UTC | |
by MeowChow (Vicar) on Jul 24, 2001 at 07:56 UTC | |
|
(MeowChow) Re: Passing match regexs as arguments to subroutines
by MeowChow (Vicar) on Jul 24, 2001 at 06:18 UTC |