Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^3: Sorting result of function call

by jbert (Priest)
on Dec 20, 2006 at 10:18 UTC ( #590876=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Sorting result of function call
in thread Sorting result of function call

Yes, I'd expect "sort subname" to mean "sort the empty list with the comparison func subname" - because "sort bareword LIST" means sort the (possibly empty) list with bareword as a comparison func.

And I'd expect "sort subname()" to mean "invoke subname to get a list, to sort with the default comparator" - because I interpret "subname()" to always mean "invoke subname".

So I'd expect your first two examples to have different behaviour (but not the behaviour we get).

But I'm not sure my expectations are in line with "documented reality", so I'm loath to say there definitely is a bug.

I'm hoping to learn something in this thread :-)


Comment on Re^3: Sorting result of function call
Re^4: Sorting result of function call
by ysth (Canon) on Dec 20, 2006 at 10:52 UTC
    There's no way for perl to perfectly satisfy here: sort subname LIST is clearly documented as using subname as the comparator in sorting LIST, and making the the optional whitespace before the '(' around a list become required would be unfortunate. But that leads to sort subname() not being interpreted as you intended. If you can train yourself to always use & on a sub call producing a list to be sorted, you'll be well off.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-12-17 23:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (40 votes), past polls