MeowChow has asked for the wisdom of the Perl Monks concerning the following question:

sub bleh { sort @_ ? @_ : 0 } print bleh qw(w h a t i s u p w i t d i s); ## prints "adhiiipssttuww"
Any takers?
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re: Evaluation Disorder
by tadman (Prior) on Apr 06, 2001 at 08:40 UTC
    Is that somehow incorrect? bleh() will return either a sorted list of its arguments @_, or 0 (sorted, to no avail).

    So you would expect to see the sorted list of input parameters, no?
    sub bleh { if (@_) { return sort @_; } else { return sort 0; } }
    Same thing, really, except that ?: doesn't use any BLOCKs.
      Update: D'oh I am completely wrong .. didn't catch the precendence (I thought the sort was coming before the trinary ?: )
        ?: binds tighter than a function, so it takes precedence, yes.
        sub bleh { sort @_ ? @_ : 0; }
        Which is the same as:
        sub bleh { sort (@_ ? @_ : 0); }
        But perhaps you meant:
        sub bleh { (sort @_) ? @_ : 0; }
        Though I'm not really sure what you mean by this at all, since you aren't really using the results of the sort for any constructive purpose.