in reply to Re: Re: Sort function issue
in thread Sort function issue
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 |