[comp.lang.perl] A gripe about catching programming errors in Perl

alanm@cognos.UUCP (Alan Myrvold) (10/26/90)

Recently, I wrote a bit of a perl script that looked something
like this:

    open(oct,"< October");
    while (<oct>) {
       print;
    }

Even though the file October exists, nothing was printed.  This
is due to my choice of oct as a filehandle, since oct is a built-in
function.

Why couldn't I have at least gotten a warning during the compile?
With perl's big collection of functions, I can't be the only one
making mistakes like this.  Is it ever proper to use a function name
where a file handle is expected?

                                          - Alan

---
Alan Myrvold          3755 Riverside Dr.     uunet!mitel!cunews!cognos!alanm
Cognos Incorporated   P.O. Box 9707          alanm@cognos.uucp
(613) 738-1440 x5530  Ottawa, Ontario       
                      CANADA  K1G 3Z4       

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (10/27/90)

In article <8974@cognos.UUCP> alanm@cognos.UUCP (Alan Myrvold) writes:
: Recently, I wrote a bit of a perl script that looked something
: like this:
: 
:     open(oct,"< October");
:     while (<oct>) {
:        print;
:     }
: 
: Even though the file October exists, nothing was printed.  This
: is due to my choice of oct as a filehandle, since oct is a built-in
: function.
: 
: Why couldn't I have at least gotten a warning during the compile?
: With perl's big collection of functions, I can't be the only one
: making mistakes like this.  Is it ever proper to use a function name
: where a file handle is expected?

Yes, it is.  The above converts the octal value found in $_ to a decimal
value, then uses that number as the filehandle.  Why you'd want to do
that is beyond me, but it's perfectly legal--the first argument of
open can be any expression yeilding a filehandle.

The manual suggests you use upper case for filehandles and labels.  There
is a REASON for that...

Larry