[H-GEN] perl question about sort()

Tony Nugent tony at linuxworks.com.au
Thu Feb 27 20:03:16 EST 2003


[ Humbug *General* list - semi-serious discussions about Humbug and     ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]

On Thu Feb 27 2003 at 10:28, Jason Parker-Burlingham wrote:

> Tony Nugent <tony at linuxworks.com.au> writes:

> > do it using sort()...  figuring out exactly how to use perl's sort()
> > function has me somewhat confused.

[ ... slow munch on lots to digest ... ]

> If there's something very specific in this example that you don't
> understand, reply to the list and point it out.  I'll happily try
> again.

The use of map{} is new to me, and the talk about schwartzian
transformation was a bit "heady".  But something did go click...

As an exercise for myself, I managed to write a little script that
sorted the password file by UID in reverse order... it was more
simple to do than I suspected.  Ok, so that's a start.

I'm still a little hazy about the origin and importance of the $a
and $b variables that "magically" appear.  For example:

>       sort { $b->{age} <=> $a->{age} } @students

Are the raw values that get compared always referred to as $a and
$b?  Do they have global scope?

> Okay, you should also read the C<sort> section of the Perl manual (run
> "perldoc -f sort") and the Perl FAQ entry on sorting
> (run "perldoc -q sort").

Now that is the most useful thing!  I wish I had known about this
way before now!  Thanks.

So often the real answer is not so much the specific information to
satisfy a particular question, but a pointer to how to go about
finding that information :-)

> jason

Thanks for your time and insight.

Cheers
Tony

--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.  See http://www.humbug.org.au/



More information about the General mailing list