In article <JBW.90Apr20205...@bucsf.bu.edu> j...@bucsf.bu.edu (Joe Wells) writes:
: (Perl 3.0 patchlevel 18) : : Why does perl accept this short program without an error: : : sort X : : What does perl think "X" is? A filehandle? A format?
The short answer is that it is a subroutine name, and since you have it a null array to sort, it never evaluates the subroutine name to find out it doesn't exist. See the man page.
The long answer is that there are a class of operators in perl called list operators, and any of them can take an optional word or scalar variable before the list. Some of them, such as "print", take it to be a filehandle. "sort" takes it to be a subroutine name. "exec" and "system" take it to be a scalar holding the real name of the program to exec. Some list operators such as "unlink" and "kill" ignore it entirely!
I know it's weird, but it does make it easier to write poetry in perl. :-)
In article <7...@jpl-devvax.JPL.NASA.GOV> lw...@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:
In article <JBW.90Apr20205...@bucsf.bu.edu> j...@bucsf.bu.edu (Joe Wells) writes: : sort X : : What does perl think "X" is? A filehandle? A format?
The long answer is that there are a class of operators in perl called list operators, and any of them can take an optional word or scalar ^^^^^^^^^^^^^^^^^^^^^^^ variable before the list. Some of them, such as "print", take it to be ^^^^^^^^ a filehandle. "sort" takes it to be a subroutine name. "exec" and "system" take it to be a scalar holding the real name of the program to exec. Some list operators such as "unlink" and "kill" ignore it entirely!
I'm confused. This seems like a highly ambiguous specification. For example, how does perl know in the following examples whether an optional word or *scalar variable* is present:
sort $X; # this could be optional variable followed by empty list, right? print $X; # ditto unlink $X; # this could be a noop according to the above
-- Joe Wells <j...@bu.edu> jbw%bucsf.bu....@cs.bu.edu ...!harvard!bu-cs!bucsf!jbw
In article <JBW.90Apr23174...@bucsf.bu.edu> j...@bucsf.bu.edu (Joe Wells) writes:
: I'm confused. This seems like a highly ambiguous specification. For : example, how does perl know in the following examples whether an optional : word or *scalar variable* is present: : : sort $X; # this could be optional variable followed by empty list, right? : print $X; # ditto : unlink $X; # this could be a noop according to the above
I believe that's one of those places where a shift-reduce conflict "does the right thing".