[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] !fwp: weird behavior with sort and unique-ing



On Thu, Jan 20, 2000 at 02:15:20PM -0800, Austin S. Lin wrote:
> 
> print "joined sorted unique list:"; 
> print join ',', sort unique_list(@list);  print "\n";
> 
> sub unique_list {
>     return keys %{{ map {($_,undef)} @_ }};
> }
> 
> 
> Prints this when run:
> 
> list:a b c d d e a b
> uniqued:abcde
> joined unique list:a,b,c,d,e
> joined sorted unique list:a,b,c,d,d,e,a,b
> 
> 
> I'm not sure why throwing a sort after the join would do this :(
> 

sort unique_list(@list) is parsing unique_list as the name of the
comparison function and (@list) as the list to sort.  What you wanted was
for unique_list(@list) to be the list to sort, with the default comparison
function.

You can disambiguate with an ampersand:

print join ',', sort &unique_list(@list);  print "\n";

Ronald

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe