[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] sorting algorithms



On Thu, Nov 09, 2000 at 09:34:09PM -0500, Scott R. Godin wrote:
> on 11/09/2000 07:05 PM, Paul McCann at pmccann@maths.adelaide.edu.au wrote:
> 
> > $gametype='assault';
> > $master_maps_list{$gametype}{'a'}=['a','titlea',60,'y',9];
> > $master_maps_list{$gametype}{'b'}=['b','titleb',73,'n',8.5];
> > $master_maps_list{$gametype}{'c'}=['c','titlec',51,'n',9.5];
> > $master_maps_list{$gametype}{'d'}=['d','titled',51,'n',9.5];
> > $master_maps_list{$gametype}{'aa'}=['aa','titled',51,'n',9.5];
> > 
> > # first a reference to allow less typing in what follows.
> > 
> > $ref=\%{$master_maps_list{$gametype}};
> 
> Nice trick. I knew this existed, but really hadn't seen it in action in the
> context of what I'm using the script for. I'll have to ponder this sort of
> usage and see if it can help me any in the future. *thanks*

But I wonder if is there a reason for creating a ref to a copy of the hash
in this case.  $master_maps_list{$gametype} is already a reference to a
hash, so you could just do this:

$ref = $master_maps_list{$gametype};

I think you'd only need to copy the hash if you want to make temporary
changes that shouldn't be reflected in the original.  Otherwise, the
simpler assignment will be more efficient.



In regards to coercing the data before sorting, I think you'll be
interested in Uri Guttman and Larry Rosler's sorting paper:

http://www.sysarch.com/perl/sort_paper.html

If you've got a lot of data, coercing the sort keys to ASCII strings and
using the builtin sort-in function certainly can be a win.


Ronald

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org