in reply to Re: Array Sort
in thread Array Sort

Not disagreeing with the strategy, however if there is a large quantity of data, shouldn't you restrict the sort element of the array to contain only the element to be sorted, as far as I can see it adds no overhead (we already have a list from the split function) and reduces the memory usage. ie
#!/usr/local/bin/perl use strict; use warnings; my @data = ('AC-BA91-CA', 'AB-BA92-CA', 'AD-BA90-CC', 'AA-BA93-CA', 'AA-BA89- +CB'); my @sorted = map {$_->[0]} sort {$a->[1] cmp $b->[1]} map {[ $_ , (split '-')[1 +] ]} @data; print "$_\n" for @sorted;
Just wondering, Utilitarian.

print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Replies are listed 'Best First'.
Re^3: Array Sort
by GrandFather (Saint) on May 10, 2011 at 08:00 UTC

    Sure. Storing just the original string and sort key is a reasonable idea if the data is very large. The little bit of extra "clutter" added was better left out of the original example though, especially as the OP may actually be working with quite different data and have different requirements for extracting the sort key than was suggested in the OP.

    True laziness is hard work