Well, totally bored here at work. I have a bunch of VBScript code (ugh!) that's sitting here doing nothing until I get more specs. Thought I would use the time to play around with a problem suggested in another node. Essentially, the author wanted to sort a list by frequency of the items in that list. Having spare time and a huge desire to maintain my limited Perl skills, I wrote the following snippet:
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 );
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?

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).


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.