in reply to Re: Using Map to Create AoA
in thread Using Map to Create AoA
[ 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:
Update: Yes it was my fault. I made the typo. I apologize to ikegami for my carelessness. Thanks to Tanktalus for mentioning it.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'] ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Using Map to Create AoA
by Tanktalus (Canon) on Oct 17, 2005 at 02:51 UTC |