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?
In reply to Re: How to call a function on each item after a split?
by MrSnrub
in thread How to call a function on each item after a split?
by MrSnrub
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |