Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: sort usersub. Message-ID: <1991Apr09.033830.737@convex.com> Date: 9 Apr 91 03:38:30 GMT References: Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 25 Nntp-Posting-Host: pixel.convex.com From the keyboard of sakoh@sraco2.us.sra.co.jp (Hiroshi &): :What's wrong with this program? : : #!/usr/bin/perl : sub as_numeric { $a <=> $b; } : : package other; : : @c = (2,3,2,6,4,2); : @d = sort main'as_numeric @c; : : for $e (@d) { : print "$e\n"; : } What's wrong is that $a and $b are compiled in the main routine, but are being passed in as $other'a and $other'b. Solutions are: 1) move the subroutine declaration below the package statement. 2) reference the vars with their $other' qualification. 3) pull out the package with caller and use an eval to get it right. perl -w points out the problem, albeit non-obviously. --tom