in reply to What's the difference between stat and sort?

Huh? Seems to work here. Both of these work for me:
perl -e 'my $lf = (sort(<*>))[-1];print $lf'
and
perl -e 'my $foo = (stat("myfile"))[7];print $foo'
.

Replies are listed 'Best First'.
Re^2: What's the difference between stat and sort?
by PetaMem (Priest) on Jul 15, 2004 at 10:03 UTC
    Aaah. As the germans say: "I get the crisis!"

    my $lf = (sort(<*>))[-1]; print $lf,"\n";
    works. While the (what I tested)
    print (sort(<*>))[-1], "\n";
    throws a
    print (...) interpreted as function at ./template.pl line 6.
    syntax error at ./template.pl line 6, near ")["
    Execution of ./template.pl aborted due to compilation errors.
    

    Bye
     PetaMem
        All Perl:   MT, NLP, NLU

      Oh that's easy, parenthesisation. Try this:
      perl -e 'print((sort(<*>))[1]);'

      Once the expression is fully inside parentheses, there is no syntax error. With the square brackets outside the parens, it must be trying to get the first element of the array returned by print(), which doesn't return an array.