[snip]

> my $acceptable = qr/^(?:sp|lp|ep12|ffp|vid|dvd|bx|bkk|cd|csd)$/;
> 
> and then using $acceptable to do the matchings, such as
> 
> grep /$acceptable/, @array
> 
> 
> it would be faster and more readable :-)

If the acceptable list is that large, using a hash would be TMTOWTDI  :-)

#!/usr/bin/perl
use strict;
use warnings;

my %acceptable = map {$_ => 1} qw/ sp lp ep12 ffp vid dvd bx bkk cd csd /;

my @a = ([qw/ cd csd cd /], [qw/ abc ed csd cd /]);

for (@a) {
 if (grep {not $acceptable{$_}} @$_) {
  print "Not acceptable\n";
 }
 else {
  print "OK\n";
 }
}

Chris


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to