in reply to substring search in an array of arrays
One useful thing to think about with grep is what it will look like as a loop.
Is the same asmy @grepnames = grep {/"ER"/} @test2;
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.my @grepnames; for my $test2item (@test2) { push @grepnames,$test2item if $test2item =~ /"ER"/; }
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.
|
|---|