in reply to Re^2: Parsing file in Perl post processing
in thread Parsing file in Perl post processing
By using qr{} I am telling Perl the string inside will be used in a regex. See http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators. The most common reason to do this is to save time when you are using the same regex over and over; I use it because it often seems to make sure Perl interprets the regex in the way I expect.
map {block} @array returns an array created by executing {block} once for each element of @array, each time assigning one value to $_.
@a=(1,2,3); @a_plus_1 = map { $_ + 1 } @a;
The block, which in this example is $_ + 1, will be execute 3 times, once for each value in @a. It will put the results also in an array, so the values in @a_plus_1 will be (2,3,4).
In my solution, I have the map return two values separated by a comma. This is one way to define a hash. You can see this using the debugger:
perl -d -e 1 Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(-e:1): 1 DB<1> %h=(1,2,3,4) DB<2> print $h{1} 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Parsing file in Perl post processing
by gbwien (Sexton) on Sep 14, 2015 at 14:11 UTC | |
by GotToBTru (Prior) on Sep 14, 2015 at 14:52 UTC | |
by gbwien (Sexton) on Sep 16, 2015 at 08:26 UTC | |
by GotToBTru (Prior) on Sep 16, 2015 at 12:36 UTC |