in reply to Variable Subroutine

Modify your subs so the subname can be passed as an argument to sort e.g
sub by_num { my($x,$y) = ($a =~ /(\d+)/, $b =~ /(\d+)/); return $x <=> $y; } sub by_abc { return $a cmp $b; } my $f = 'by_num'; my @args = qw/ foo1 bar2 baz3 /; print "$f - ", sort($f @args), $/; $f = 'by_abc'; print "$f - ", sort($f @args), $/; __output__ by_num - foo1bar2baz3 by_abc - bar2baz3foo1
But your solution is fine as it stands (although you need to call the function in the sort block e.g sort { &$sort_network{$sortby} } keys %networks).
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Variable Subroutine
by tombmbdil (Beadle) on May 27, 2003 at 17:20 UTC
    Aha! That's much better. I remember reading about that sort feature, but it didn't really sink in. Thanks.