in reply to Re^3: Why does 'print shift sort @array' not work?
in thread Why does 'print shift sort @array' not work?

We both known Perl is very finicky when parens are omitted. But
print [sort @array]->[0]

would still be simpler, no?

Replies are listed 'Best First'.
Re^5: Why does 'print shift sort @array' not work?
by Fletch (Bishop) on Feb 26, 2009 at 20:40 UTC

    But that's a whole character longer . . . :) (But then again the square version requires hitting shift one less time so it has that going for it :)

    print +(sort @array)[0]; print [sort @array]->[0];

    Possibly could an interesting benchmark if anyone's so inclined: does slicing the value off the stack beat constructing the anonymous arrayref (which gets tossed immediately) then deref'ing, and what the falloff is as @array grows.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re^5: Why does 'print shift sort @array' not work?
by hbm (Hermit) on Feb 26, 2009 at 21:07 UTC

    Aren't the following functionally equivalent, i.e. Sort, make an array and a reference to it, dereference it, get the [first] item?

    print [sort @array]->[0]; print @{[sort @array]}[0];
      Aren't the following functionally equivalent,
      Technically, no. [sort @array]->[0]; does return a single element. @{[sort @array]}[0]; however is a slice with one element. I would have expected it to warn - just as @array[0] will warn. The PC way to write it is:
      print ${[sort @array]}[0];