After writing this code, I realized many people may have just not realized this is possible, so I think posting it here would make people think more about it.
I was writing a simple script wich would receive a attr=value,attr2=value2 string and automatically I wrote:
my %attrs = map { split /=/ } split /,/, $attr;
Well, the trick is that map doesn't have to return the same number of elements of the list it receives. If you returns a list inside a map, the resulting list will have more elements than the input list.
This sounds very intuitive to me, but maybe it's not for others...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing attributes in one line using map
by izut (Chaplain) on Sep 25, 2006 at 10:34 UTC | |
|
Re: Parsing attributes in one line using map
by davidrw (Prior) on Sep 25, 2006 at 12:44 UTC | |
by jhourcle (Prior) on Sep 25, 2006 at 13:38 UTC | |
|
Re: Parsing attributes in one line using map
by jdporter (Paladin) on Sep 25, 2006 at 14:53 UTC |