develooper Front page | perl.perl5.porters | Postings from December 2000

[ID 19991001.003] sort(sub(arg)) misparsed as sort sub args

Thread Next
From:
Stephen P. Potter
Date:
December 21, 2000 11:50
Subject:
[ID 19991001.003] sort(sub(arg)) misparsed as sort sub args
Message ID:
200012212050.PAA13941@spotter.yi.org
Still true as of 8221.

-spp

SHORT STORY:

 I found this bug (at least I consider it a bug) while trying to apply
 sort to the output of a sub.
 I tried:
   sort(routine($arg))
 and was surprised to find the output consisting of a one-element list,
 consisting only of $arg!
 Apparently this parses as a case of
   sort SUBNAME LIST

 I can understand that as a correct reading for
   sort routine $arg
 But not for
   sort(routine($arg))

 I note that
   sort +(routine($arg))
 does the Right Thing, as does
   sort( (), routine($arg))


 ***************************************************************************
 LONG STORY (with example code, and perl -V output)

 Note the output of this sample program:

 ttyp5 sburke ~ stonehenge 20: perl
 BEGIN{$^W = 1}
 sub zoz { "one!", "two!", "three!" }; # ignores its @_
 print ">", join(" ",              sort(zoz(5) ) ), "\n";
 [I hit ctrl-d]
 Unquoted string "zoz" may clash with future reserved word at - line 3.
 >5

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About