develooper Front page | perl.beginners | Postings from June 2003

Re: find uniq paths in @INC

Thread Previous | Thread Next
From:
John W. Krahn
Date:
June 28, 2003 21:41
Subject:
Re: find uniq paths in @INC
Message ID:
3EFE6DF9.E568D87C@acm.org
Harry Putnam wrote:
> 
> "John W. Krahn" <krahnj@acm.org> writes:
> >
> > And then get the sorted list like this:
> >
> > @sorted = sort { $name{ $a } cmp $name{ $b } } keys %name;
> 
> I've seen that in books and stuff but was never able to fathom out
> how it does what it does.  So never actually used it in code.
> I still don't see how it does what it does but at least an up close
> and personal example of what it does.... Thanks

"keys %name" passes a list of the keys from the %name hash to sort. 
Inside the sort code block the $a and $b variables contain the current
keys to be sorted and we use those keys to reference the current values
of %name and sort those.  Then the list of keys sorted by values is
stored in the @sorted array.


John
-- 
use Perl;
program
fulfillment

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About