in reply to Pattern matching across an array

Your confusion is due to $", the list separator, which defaults to a space. Thus, "@array" has the value A B C D E. You simply need to make allowance for this

Beware: if you set the separator to '', or use join as robartes has suggested, then you won't differentiate between qw/AB CD E/ and qw/A B C D E/, which may or may not be what you want (similarly, if you manage to get a space into one of the array values, this may cause problems.)

--
Tommy
Too stupid to live.
Too stubborn to die.

Replies are listed 'Best First'.
Re: Re: Pattern matching across an array
by ihb (Deacon) on Feb 05, 2003 at 22:44 UTC

    But @array isn't interpolated anywhere. The =~ operator doesn't impose any magical interpolation of the LHS. Instead, @array is in scalar context, and @array in scalar context is the length of the array.

    my @foo = 1..5; print @foo =~ /5/; # prints '1' for success.
    Update: Oops, sorry, my bad. Missed the parenthesis in the OP.

    ihb

      If you notice, Foxcub has tried stringifying the array, by enclosing it in quotes. That's where the interpolation happens.

      my @foo = 1..5; print "@foo" =~ /1 2 3 4 5/; # prints '1' for success.

      --
      Tommy
      Too stupid to live.
      Too stubborn to die.