december has asked for the wisdom of the Perl Monks concerning the following question:
Hello, fellow monks.
I have the following bloated code in a cgi script I'm writing:
@filesImage = sort { $a->{name} cmp $b->{name} } @filesImage; @filesAudio = sort { $a->{name} cmp $b->{name} } @filesAudio; @filesText = sort { $a->{name} cmp $b->{name} } @filesText; @filesUnknown = sort { $a->{name} cmp $b->{name} } @filesUnknown; @filesDirectory = sort { $a->{name} cmp $b->{name} } @filesDirectory;
I'm planning to rewrite this code with some references, something along the lines of:
foreach (\@list1, \@list2) { @$_ = sort {$a cmp $b} @$_; }
... but when I've tried to use 'map' for this, just as an excercise, I couldn't find the right syntax to stop map from merging the lists. Out of curiosity, could this be rewritten as a one-liner with map, and if so, how?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: simplify sorting of multiple lists
by merlyn (Sage) on Jul 20, 2004 at 16:51 UTC | |
by december (Pilgrim) on Jul 20, 2004 at 17:20 UTC | |
|
Re: simplify sorting of multiple lists
by ccn (Vicar) on Jul 20, 2004 at 16:48 UTC | |
by december (Pilgrim) on Jul 20, 2004 at 17:06 UTC |