in reply to Re: Re: Sort function issue
in thread Sort function issue

In that case:
use strict; use warnings; main(); xyz(); sub main{ my $h; foreach (1..20){ $h->{$_} = int rand (100); } my $by_val = make_sort($h); foreach (sort $by_val keys %{$h}){ print "$_","\t",$h->{$_}; } print "\n"; } sub xyz { my $k; foreach (1..20){ $k->{$_} = int rand (100); } my $by_val = make_sort($k); foreach (sort $by_val keys %{$k}){ print "$_","\t",$k->{$_}; } print "\n"; } sub make_sort { my $dat = shift; return sub { $dat->{$a} <=> $dat->{$b} }; }

Replies are listed 'Best First'.
Re: Re: Re: Re: Sort function issue
by shemp (Deacon) on Jun 24, 2003 at 21:42 UTC
    Yes that should work. Strict was the issue. In general I dont want a direct reference to the data structure being sorted, since i want to put the sort function in a required library, which has always been somewhat of an issue for me.
    I very much like this solution - thanks much