PerlingTheUK has asked for the wisdom of the Perl Monks concerning the following question:
I am not good at writing compact code but I did not see any way to simplify this to a one liner or so. I am looking forward to your suggestions.my %vals=( 1 => '0', 2 => '3', 3 => '5'); my @arr = ( 0,1,2,3,4,5,6 ); my @res; for my $key ( sort{ $a <=> $b } keys %vals ){ push @res, $arr[$vals{ $key }]; } print join (',', @res );
but then thought there must be an even more compact way.print join (',', @arr[@res] );
push @res, $vals{ $key };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting an array slice of value assignments in a hash
by merlyn (Sage) on Jun 03, 2005 at 10:22 UTC | |
by ZlR (Chaplain) on Jun 03, 2005 at 10:38 UTC | |
|
Re: Getting an array slice of value assignments in a hash
by tlm (Prior) on Jun 03, 2005 at 12:48 UTC | |
|
Re: Getting an array slice of value assignments in a hash
by Tomtom (Scribe) on Jun 03, 2005 at 10:21 UTC | |
|
Re: Getting an array slice of value assignments in a hash
by ysth (Canon) on Jun 03, 2005 at 10:18 UTC | |
|
Re: Getting an array slice of value assignments in a hash
by Roy Johnson (Monsignor) on Jun 03, 2005 at 16:13 UTC |