[Omaha.pm] /AAA|BBB/
Robert A. Fulkerson
robert.fulkerson at gmail.com
Thu Feb 2 11:06:31 PST 2006
Of course, if you're not going to use backreferencing ($1, $2, etc) with
those parens, you'll probably want to turn off the backreferencing with ?:
inside the parens; no need to create backreferences if you're not going to
use 'em:
foreach (qw(AAXXBB AAYBB AAXYBB AAYBB AYBB)) {
> printf("%-7s", $_);
> print (($_ =~ /^AA(XX|Y)BB$/) ? "yes " : "no ");
> print (($_ =~ /^AAXX|YBB$/) ? "yes " : "no ");
> print "\n";
> }
>
> $ perl j.pl
> AAXXBB yes yes
> AAYBB yes yes
> AAXYBB no yes
> AAYBB yes yes
> AYBB no yes
$ cat x.pl
foreach (qw(AAXXBB AAYBB AAXYBB AAYBB AYBB))
{
printf("%-7s", $_);
print (($_ =~ /^AA(?:XX|Y)BB$/) ? "yes " : "no ");
print (($_ =~ /^AAXX|YBB$/) ? "yes " : "no ");
print "\n";
}
AAXXBB yes yes
AAYBB yes yes
AAXYBB no yes
AAYBB yes yes
AYBB no yes
-- b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/omaha-pm/attachments/20060202/5c336f14/attachment.html
More information about the Omaha-pm
mailing list