Gohaku wrote:
I am trying to sort an array returned by a subroutine.

No, you are not. You are trying to sort a list returned by a subroutine.

I would like to know why sort doesn't work on a Returned Array and
why the returned array has to be parenthesized.

#sortarray.pl
print join("\n",sort arraytest()  ),"\n";

#This works --> print join("\n",sort (arraytest())  ),"\n";
#Don't know why this works --> print join("\n",sort &arraytest()  ),"\n";

sub arraytest()
{
    my (@array) = qw( 1 2 3 9 8 7 );
    return @array;
}

The sort() function is to be used in any of these ways:

    sort SUBNAME LIST
    sort BLOCK LIST
    sort LIST

Accordingly,

    sort arraytest()

sorts the empty LIST () in accordance with SUBNAME arraytest, while

    sort ( arraytest() )

sorts the list returned by arraytest().

HTH

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to