Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: why don't filehandles have punctuation before their name?

by Yohimbe (Pilgrim)
on Apr 24, 2001 at 03:19 UTC ( [id://74909]=note: print w/replies, xml ) Need Help??


in reply to why don't filehandles have punctuation before their name?

They can have punctuation
use FileHandle; $fh = new FileHandle; if ($fh->open("< file")) { print <$fh>; $fh->close; }
File handles are just a scalar, IIRC, and the uppercasing is just a convention, a holdover from the other languages from whence it came.
--
Jay "Yohimbe" Thorne, alpha geek for UserFriendly

Replies are listed 'Best First'.
Re: Re: why don't filehandles have punctuation before their name?
by chipmunk (Parson) on Apr 24, 2001 at 08:21 UTC
    Actually, filehandles (and dirhandles) are not just scalars. In fact, if you look at the value returned by new FileHandle, you will see that it is a reference to a GLOB.

    Because filehandles (and dirhandles) don't have a special syntax, like scalars/arrays/hashes, you have to refer to the entire glob instead. This is why you see code like:

    sub myprint { my($fh) = @_; print $fh "Hello world.\n"; } myprint \*STDOUT;
    The FileHandle and IO::Handle modules make it more convenient to use arbitrary handles, because they hide the reference-to-glob syntax.
Re: Re: why don't filehandles have punctuation before their name?
by sierrathedog04 (Hermit) on Apr 24, 2001 at 05:52 UTC
    Filehandles are uppercased so that the introduction of new perl keywords (which are always lowercased) do not break existing Perl scripts. Larry has endorsed this convention.

    It seems to me, however, that new keywords could still break existing scripts if those scripts included subroutines with the same names as the keywords. So to be consistent we ought to name our subroutines in all uppercase as well, or at least throw in a few uppercase letters in our subroutine names.

      Perhaps you didn't notice the addition of BEGIN, END, CHECK, DESTROY, and INIT, etc. (: In fact, I think you should name subroutines with mixed case and should avoid the bareword-as-filehandle syntax. The bareword-as-filehandle syntax caused lots of problem even way back in Perl4. It is nice to have an alternative to it in Perl5.

              - tye (but my friends call me "Tye")
        99 percent of the code I see posted here uses barewords as filehandles. Is there some other way to do it? How?
      So to be consistent we ought to name our subroutines in all uppercase as well, or at least throw in a few uppercase letters in our subroutine names.
      I prefer to include at least one _. As far as I know, no built-in functions contain underscores, and probably never will.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://74909]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-03-29 12:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found