map is written before grep but is executed after...
map executes commands for each item in the list
(perldoc -f map)
while grep returns items from list for which the expression evaluated is true
(perldoc -f grep)
Here, the list comes from grep command which extracts fields from @F array that match /<(.*)>/
for each field, map executes:
- s/<|>//g; => remove all < and > from item
- "$_\n" => concatenate item with "\n" char
each item is in $_ variable, map could also be written as:
Code:
map {$_ =~ s/<|>//g; "$_\n"}
(edit)
I found that substitution could be done in grep expression, so no need to use map
Code:
perl -ane 'print grep {s/<+(.*)>/$1\n/} @F' email.txt
- I used ' s/<+(.*)>/$1\n/ ' to match 1 or more '<' like: "<<user1@home.com>"
This substitution could also work...
Code:
perl -ne 'print if s/.*?<+(.*?)>\s?\n?/$1\n/g' email.txt