in reply to Re: substring search in an array of arrays
in thread substring search in an array of arrays

"ER" is misleading. It implies ER is text while it's really a regex. Use /ER/ instead.

Don't pretend the first argument of split is text.
Don't pretend the RHS of =~ is text.

my @grepnames = grep { $_->[0] =~ /ER/ } @test2; print(join(', ', @$_), "\n") for @grepnames;

Update: Fixed LHS to say RHS.

Replies are listed 'Best First'.
Re^3: substring search in an array of arrays
by BrowserUk (Patriarch) on Feb 14, 2008 at 22:46 UTC

      Sure thing. An example where the confusion leads to a difference would be $_[0] =~ "Dr.". It doesn't search for "Dr.", it searches for a three char string starting with "Dr". I mentioned split because split '|', ... is a similar common error and a reference to past threads on the topic.

        In other words, whatever is on the RHS of =~ acts exactly like a regex...regardless of whether it is in // delimiters or "" delimiters. Or even if it is contained within a variable. That's exactly what I thought.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.