geary@acm.org has asked for the wisdom of the Perl Monks concerning the following question:

So, let's say, purely for the sake of argument, that I have a function like:

sub rv (@) { reverse @_; };
and I want to call it in this context:
sort rv @list;
Perl won't let me because it thinks I'm trying to use &rv as the comparison function for sort. I could say:
sort(rv(@list));
but that doesn't look as cool.

This works:

sort reverse @list;
How do get perl to treat &rv the same way?

======= (added in 2019)

This has been sitting at the back of my mind for the past seven years, and I have finally come back to it.

I wasn't clear in my original question on what I wanted to know, and as a result all the answers missed the point.

I don't want to put any of the code above in a program. I want to understand why this difference exists.

Replies are listed 'Best First'.
Re: Why are my functions second-class citizens?
by Old_Gray_Bear (Bishop) on Feb 15, 2012 at 17:01 UTC
    Don't code for 'cool', code for clarity.

    ----
    I Go Back to Sleep, Now.

    OGB

Re: Why are my functions second-class citizens?
by choroba (Cardinal) on Feb 15, 2012 at 16:43 UTC
Re: Why are my functions second-class citizens?
by LanX (Saint) on Feb 15, 2012 at 16:52 UTC
    Some people want this DWIM functionality, which inhibits to Do What You Mean.

    Instead of fiddling with this magical syntax, I'd recommend writing a function my_sort with a clear interface to do what you want.

    Cheers Rolf

Re: Why are my functions second-class citizens?
by JavaFan (Canon) on Feb 15, 2012 at 17:55 UTC
    If you don't like the sort-cut sort is offering you, you can always be explicit:
    sort {$a cmp $b} rv @list;