in reply to sort mechanism

This brings up an interesting question. Reading the Library notes on sort seem to indicate that it will return a list (of sorted values).
So, the following code does what you'd think it does: print (3, 2, 1) ? "yes" : "no";
However, if you change it to: print sort (3, 2, 1) ? "yes" : "no"; you get "no", not "yes".

Why does this behavior happen? I'm obviously not understanding something about the sort function.

Replies are listed 'Best First'.
Re: Re: sort mechanism
by MeowChow (Vicar) on Apr 06, 2001 at 21:54 UTC
    I just bumped into this behavior when asking the confused question in Evaluation Disorder. As it turns out, sort always returns false in a scalar context, not the length of the returned list, as one might assume.
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      My question then becomes where would this be documented? How would I known this without playing around? (Granted, the playing was still fun and enlightening, but that's not the point.)
        It should be documented in sort, but it is not. Probably because they didn't think up useful behaviour and didn't want to document intentionally useless behaviour. (Though I would have preferred to see fatally useless behaviour, or at least a warning...

        Personally I think that sort in scalar context should sort the array in place. But that is just me...