blahblahblah has asked for the wisdom of the Perl Monks concerning the following question:
I found a description of this very same problem, and a solution (use prototypes) in japhy's Resorting to Sorting tutorial (in the very last section). However, I cut and pasted his example script into a file, and it didn't work: it printed the original unsorted data.#!/usr/footprints_perl/bin/perl -- package joe; my @names = ('joe', 'aaron'); package FP; sub sortNames ($$) { print "$a vs $b\n"; return $a cmp $b; } package joe; my @sorted = sort {FP::sortNames} @names; print "sorted : @sorted\n"; __END__ vs sorted : joe aaron
What's the typical way to get around this? Any idea why japhy's example doesn't work?
-Joe
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sort sub in a different package
by dragonchild (Archbishop) on Apr 21, 2005 at 15:05 UTC | |
by bart (Canon) on Apr 21, 2005 at 15:17 UTC | |
by polettix (Vicar) on Apr 21, 2005 at 16:20 UTC | |
by BrowserUk (Patriarch) on Apr 21, 2005 at 15:11 UTC | |
|
Re: sort sub in a different package
by johnnywang (Priest) on Apr 21, 2005 at 18:57 UTC |