in reply to Re^8: comparing contents of two arrays and output differences
in thread comparing contents of two arrays and output differences

PitifulProgrammer:

Yeah, map is one of my favorite bits. It's a simple way to build one list given another list. You need only give it a chunk of code to call for each element in the list, and whatever it returns is the content of the new list.

my @list = (1, 2, 3, 4, 5); # makes list: 2, 4, 6, 8, 10 my @even_numbers = map { $_*2 } @list; # makes list: 1, 4, 9, 16, 25 my @squares = map { $_*$_ } @list; # makes list: 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 my @repeated_list= map { $_, $_ } @list; @list = qw(foo bar baz); # makes list 'foo', 'bar', 'baz' my @single_quoted = map { "'$_'" } @list;

...roboticus

When your only tool is a hammer, all problems look like your thumb.