On May 7, Jason Dusek said:

>But if I have a long list of suffixes, then I would like to store the
>suffixes in an array, and then evaluate the array in my regular
>expression. What does this? I've tried:
>
>   @SUFF = (fish,foul);

I think you mean @SUFFIXES.  That's the array you use below...

>   foreach (@ARGV) {
>     print if (/\.(@SUFFIXES)$/);
>   }

The problem is that @SUFFIXES expands to "fish foul" inside a string or a
regex, and you need it to be "fish|foul".  There are a couple ways to
accomplish what you want:

  my $pat = join "|", @SUFFIXES;
  foreach (@ARGV) {
    print if /\.($pat)$/;
  }

Or:

  foreach (@ARGV) {
    local $" = "|";
    print if /\.(@SUFFIXES)$/;
  }

And both of those regexes can have the /o modifier put on the end of them,
if you're sure @SUFFIXES won't change during the execution of your
program.

  foreach (@ARGV) {
    local $" = "|";
    print if /\.(@SUFFIXES)$/o;
  }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN    [Need a programmer?  If you like my work, let me know.]
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
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