in reply to Named Sort Subs with Strict?
You need to have the variables accessible by by_americentric(). There are a few ways to do this. One way is to put both of the subroutines inside an enclosing block, like this:
{ my (%country, %state, %msaname); sub do_msalist { my @msakeys = @_; foreach(sort by_americentric @msakeys) { #... } } sub by_americentric { $country{$b} cmp $country{$a} or $state{$a} cmp $state{$b} or $msaname{$a} cmp $msaname{$b} or $a <=> $b; } }
Or, you can define the associative arrays as package variables with 'use vars'. Or you can just put by_americentric in as a blockin do_msalist, and call it that way:
That'll work if you only call by_americentric right there. But it's harder to read.sub do_msalist { my @msakeys = @_; foreach(sort { $country{$b} cmp $country{$a} or $state{$a} cmp $state{$b} or $msaname{$a} cmp $msaname{$b} or $a <=> $b; } @msakeys) { #... } }
stephen
|
|---|