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

Dear roboticus

That is pretty amazing, I read about map, but at that time, I could not think about an application. That is neat line of code, I'll try to memorize it for the future.

Thanks a lot for your help, I will go back to the code later and post my result(s).

Thank you very much for taking the trouble and for your explanations. I should have joined the forum much earlier :)

Kind regards

C.
  • Comment on Re^8: comparing contents of two arrays and output differences

Replies are listed 'Best First'.
Re^9: comparing contents of two arrays and output differences
by roboticus (Chancellor) on Jan 05, 2015 at 19:01 UTC

    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.