Perl Grep and Map



All,

I have an array whereby each element in that array is of the following format:

@myNames = ('a b', 'c d', 'e f', 'g h', 'i j');

However, I am only interested in grepping the second part of each element - i.e. b, d, f, h and j.

How do I grep for second part? Would Map be helpful?

I get the entire element returned and not the section of that element that I am after.



Grep is a boolean test. Does it match? If so, we want it.

If you are modifying the data, map works better.

my @lastNames = map {(split / /)[1]} @myNames;