On Thu, Mar 20, 2008 at 2:02 PM, John W. Krahn <[EMAIL PROTECTED]> wrote:
snip
>  >         print '$x[', $1 ? '0' : '1', "] matched.\n";
>
>            print "\$x[", @- - 1, "] matched.\n"
snip

That only works if we assume that $x[0] and $x[1] are free of captures
themselves:

#!/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[', @- - 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/


Reply via email to