On Thu, Mar 20, 2008 at 1:30 PM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote:
snip
> if ( /($x[0])|($x[1])/ ) {
> print '$x[', $1 ? '0' : '1', "] matched.\n";
> }
snip
Since you cannot necessarily predict what $x[0] will hold, you should
probably be testing $1 for definedness not truth:
#!/usr/bin/perl
use warnings;
use strict;
my @x = (
qr/0/,
qr/foo/
);
$_ = 0;
if (/($x[0])|($x[1])/) {
print '$x[', $1 ? '0' : '1', "] matched.\n";
}
if (/($x[0])|($x[1])/) {
print '$x[', defined $1 ? '0' : '1', "] matched.\n";
}
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/