Is there any way of eliminating the temporary variable %freqs? I hate synthetic code (code that solves a coding problem, not the problem the program is designed for) and it's bugging me. Or is this one of those age-old "FAQ" questions that I should already know the answer to?use warnings; use strict; use Data::Dumper; my @vals = qw( 1 2 3 1 3 3 3 43 bob 2 bob 6 2 ); my %freqs; $freqs{$_}++ foreach @vals; my @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, $freqs{ $_ } ] } keys %freqs; print Dumper( \@sorted );
Yeah, I know. It's a trivial post, but like I said, I am bored out of my skull here.
Incidentally, I am returning to the US in April (and will be programming in Perl again!!!!) and will be bidding a sad farewell to my newfound friends here in the Netherlands: kudra, ar0n, and h0mee (who was here visiting).
Cheers,
Ovid
Update: Once again, tilly makes me feel stupid :)
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 1: Sort on boredom
by tilly (Archbishop) on Mar 23, 2001 at 18:09 UTC | |
|
Re: Sort on boredom
by petral (Curate) on Mar 23, 2001 at 22:46 UTC | |
by Ovid (Cardinal) on Mar 23, 2001 at 23:44 UTC | |
by petral (Curate) on Mar 24, 2001 at 02:49 UTC |