Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I humbly seek wisdom. Can I use an array (probably in list context) on the left hand side of a regexp match operation?
(@vals) =~ m/[$chars]/;
or more specifically:
(values(%hash)) =~ m/[$chars]/;

Replies are listed 'Best First'.
Re: Array as LHS on string match
by Fletch (Bishop) on Aug 10, 2007 at 20:03 UTC

    You're probably after grep, which will return the elements of a list for which an expression or block evaluates to a true value.

Re: Array as LHS on string match
by FunkyMonk (Bishop) on Aug 10, 2007 at 20:04 UTC
    Applying pattern match (m//) to @array will act on scalar(@array) at / +home/scripts/x.pl line 51.

    It would of been quicker for you to just try it yourself.

      touchee' Very sorry to waste your time.
Re: Array as LHS on string match
by runrig (Abbot) on Aug 10, 2007 at 20:06 UTC
    Yes you can. But it probably doesn't do what you want it to do. What do you want it to do?
      Fletch had it right. I was lookign for something like exists to work on values instead of keys (as in the second example using a hash).
Re: Array as LHS on string match
by DACONTI (Scribe) on Aug 10, 2007 at 20:19 UTC
    maybe this example could help...
    my $line=' this or that '; my @patterns= ( $line =~ /\s*(\S*)\s*(\S*)\s*(\S*)/ ); print join('-',@patterns); # prints this-or-that