in reply to How to call a function on each item after a split?
my ($item1, $item2, $item3, $item4, $item5) = map { clean($_); } split(/\|/, $str);
makes each item either "1" or "" based on (I guess) whether there's empty space between the "item" string and the pipe symbol.
However, this line:
my ($item1, $item2, $item3, $item4, $item5) = map { clean($_); $_; } split(/\|/, $str);
...does EXACTLY what I want in only one line, no matter how many items I have. Many thanks! Question, though: I don't exactly see what is going on with the added $_;. It's not returning a value, since this is not a subroutine. It's not changing the value of $_;. I guess what it does is it tells map to return $_ as opposed to the return value of the previous statement. Is that accurate?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to call a function on each item after a split?
by GrandFather (Saint) on Oct 08, 2012 at 23:47 UTC |