On May 30, Mark Salazar said:
>I was recently bitten by this, and it's not clear to me (and others) if
>this is correct Perl behavior or not.
>
>If you have a user defined function 'func' that returns a list and you'd
>like to sort that return value it's reasonable to try:
>
> sort(func(@list));
>
>but apparently Perl interprets this as:
>
> sort func @list;
I've been bitten by that before. Even doing:
sort foobar();
becomes
sort foobar ();
which you have to admit is rather silly.
>thereby using 'func' as an ordering function instead of first processing
>'@list' with 'func' then sorting. Now I've read the stuff on page 1 of
>PERLFUNC(1) about parenthesis and whitespace being optional, but still
>this just strikes me as wrong. No?
This is due to Perl's parsing. To get around this, you can preceed the
function call with a unary + like this:
sort +foobar(@args);
or with an ampersand:
sort &foobar(@args);
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **