[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] /AAA|BBB/



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