Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: why does sort with uniq not work together

by 2teez (Priest)
on Nov 27, 2013 at 12:58 UTC ( #1064606=note: print w/ replies, xml ) Need Help??


in reply to why does sort with uniq not work together

Hi david2008,
If you use warnings; you would have seen this message: Sort subroutine didn't return single value at line ...
so using this

print "sorted unique results\n"; print Dumper( [ sort( uniq( @x, @y ) ) ] );
would resolve the issue. Try it

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: why does sort with uniq not work together
Download Code
Re^2: why does sort with uniq not work together
by hdb (Prior) on Nov 27, 2013 at 13:09 UTC

    Yes, but why?

      Hi hdb,
      Yes, but why?
      Checking sort documentation you will find this:

      Warning: syntactical care is required when sorting the list returned from a function. If you want to sort the list returned by the function call "find_records(@key)", you can use:
      @contact = sort { $a cmp $b } find_records @key; @contact = sort +find_records(@key); @contact = sort &find_records(@key); @contact = sort(find_records(@key));
      Among other things..
      That shows it can as well use: print Dumper( [ sort &uniq( @x, @y )  ] ); showing the list to be sorted is returned from a function.

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

        Thanks a lot!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1064606]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2015-07-03 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (48 votes), past polls