One useful thing to think about with grep is what it will look like as a loop.

my @grepnames = grep {/"ER"/} @test2;
Is the same as
my @grepnames; for my $test2item (@test2) { push @grepnames,$test2item if $test2item =~ /"ER"/; }
After looking at it in this format, I believe it's easier to notice that we're trying to match each item against an arrayref instead of the first element in the array.

Another thing I noticed is I think you're confused on how the eq operator works. This operator sees if the string before the operator is exactly the same as the string after the operator. So the only thing that would evaluate to true in the comparison is "ER" eq "ER".

The last thing I noticed is that regexps treat quote characters as literal quote characters instead of designating a string. So "XERXES" wouldn't match the pattern /"ER"/ but 'X"ER"XES' would.


In reply to Re: substring search in an array of arrays by lackita
in thread substring search in an array of arrays by jgatrell42

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.