"Pete Emerson" <[EMAIL PROTECTED]> wrote in message:
> Is there an elegant way to make sure that a string contains a list of
> strings, but not necessarily in any particular order? Here's how I'm doing
> it:
>
> #!/usr/bin/perl -w
>
> use strict;
> my @strings=qw(onetwothree threeonetwo onetwonope);
> my @matches=qw(one two three);
> foreach my $string (@strings) {
> my $success=1;
> foreach my $match (@matches) {
> ($string=~/$match/) ? (next) : ($success=0);
> last;
> }
> ($success) ? (print "$string matches.\n") : (print "$string does not
match.\n");
> }
>
try:
#!/usr/bin/perl -w
use strict;
my $reg = join('|',qw(one two three));
for(qw(onetwothree threeonetwo onetwonope notthere)){
print "$_ matches\n" and next if(/$reg/o);
print "$_ does not match\n";
}
__END__
prints:
onetwothree matches
threeonetwo matches
onetwonope matches
notthere does not match
david
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]