in reply to Re: Using Map to Create AoA
in thread Using Map to Create AoA

Dear ikegami,
[ split(" ", $arr->[$_]), $_ ] would be better.
Thanks for your response. But please correct me if I'm wrong. Your solution above does not give the index, theirs do. Here is the example:
my $arr = ['A -4 C', 'C -4 B', 'B -4 A', 'A -2 C', 'C -3 B']; my @res = decomp_a2aoa_wth_idx($arr); sub decomp_a2aoa_wth_idx { my $arr = shift; return map { [ split (" ",$arr->[$_],$_) ] } (0 .. @{$arr}-1); } __END__ # Prints this result $VAR1 = [ ['A','-4','C'], ['C -4 B'], ['B','-4 A'], ['A','-2','C'], ['C','-3','B'] ];
Update: Yes it was my fault. I made the typo. I apologize to ikegami for my carelessness. Thanks to Tanktalus for mentioning it.

---
neversaint and everlastingly indebted.......

Replies are listed 'Best First'.
Re^3: Using Map to Create AoA
by Tanktalus (Canon) on Oct 17, 2005 at 02:51 UTC

    ikegami's solution does - your typo doesn't. Note the location of the parenthesis - they are very important. IMO, this is an advantage of the AoH solution - it's very clear what is going on. ikegami's solution works to the original spec (I'm not so good at following specs - I like to make my code more flexible than many specs allow ;-}) as he presented it.