Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
why doesn't "sort X" give an error
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Joe Wells  
View profile  
 More options Apr 21 1990, 5:48 pm
Newsgroups: comp.lang.perl
From: j...@bucsf.bu.edu (Joe Wells)
Date: 21 Apr 90 00:50:05 GMT
Local: Fri, Apr 20 1990 8:50 pm
Subject: why doesn't "sort X" give an error
(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?

Puzzled,

--
Joe Wells <j...@bu.edu>
jbw%bucsf.bu....@cs.bu.edu
...!harvard!bu-cs!bucsf!jbw


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Wall  
View profile  
 More options Apr 24 1990, 2:14 am
Newsgroups: comp.lang.perl
From: lw...@jpl-devvax.JPL.NASA.GOV (Larry Wall)
Date: 23 Apr 90 16:15:50 GMT
Local: Mon, Apr 23 1990 12:15 pm
Subject: Re: why doesn't "sort X" give an error
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.    :-)

Larry


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joe Wells  
View profile  
 More options Apr 24 1990, 7:32 am
Newsgroups: comp.lang.perl
From: j...@bucsf.bu.edu (Joe Wells)
Date: 23 Apr 90 21:48:41 GMT
Local: Mon, Apr 23 1990 5:48 pm
Subject: Re: why doesn't "sort X" give an error

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Larry Wall  
View profile  
 More options Apr 24 1990, 10:40 am
Newsgroups: comp.lang.perl
From: lw...@jpl-devvax.JPL.NASA.GOV (Larry Wall)
Date: 24 Apr 90 00:18:42 GMT
Local: Mon, Apr 23 1990 8:18 pm
Subject: Re: why doesn't "sort X" give an error
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".

Larry


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »