Re: Array help almost correct
From: Chris Charley (charley_at_pulsenet.com)
Date: 05/26/04
- Next message: Nancy McMullin: "DBI and fetchrow"
- Previous message: Wiggins D Anconia: "Re: HTTP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: <beginners@perl.org> Date: Wed, 26 May 2004 16:23:17 -0400
[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
- Next message: Nancy McMullin: "DBI and fetchrow"
- Previous message: Wiggins D Anconia: "Re: HTTP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|