Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: Passing filehandle to sub

by arthas (Hermit)
on Jun 09, 2003 at 12:27 UTC ( [id://264315]=note: print w/replies, xml ) Need Help??


in reply to Re: Passing filehandle to sub
in thread Passing filehandle to sub

Hi broquaint!

I've got a question: since it seems that opening a file using a variable (instead of a bare word) only has advantages, like in this case, is there a reson or particular situation where it's better to use a bare word?

Thanks, Michele.

Replies are listed 'Best First'.
Re: Re: Re: Passing filehandle to sub
by broquaint (Abbot) on Jun 09, 2003 at 13:23 UTC
    is there a reson or particular situation where it's better to use a bare word?
    Under the assumption that you're using 5.6+ I can't really think of any practical situations where a bareword filehandle is preferable to a lexical variable. Sure it's potentially less characters, by general practice visually distinctive in code and doesn't incur the overhead of a lexical variable (which, to be honest, is pretty much negligible in all but the most process intensive of operations) but I can't think of any practical situations where these factors outweigh the use of a lexical filehandle. I say practical situations because a bareword filehandle is great for obfuscation and golfing, but in code at large I'd say lexical filehandles would be prefered. If any monks can think of a situation where a bareword filehandle is indeed preferable to a lexical filehandle then please reply below.
    HTH

    _________
    broquaint

      Perhaps you are familiar with the saying: "You can't teach an old dog new tricks"?

      I (and I'm sure many others) learned to use bareword filehandles. If I remember to use a variable one time, chances are the next time I'll revert back to a bareword.

      If any monks can think of a situation where a bareword filehandle is indeed preferable to a lexical filehandle then please reply below.

      When it is already open for you such as ARGV, ARGVOUT, and the STD* filehandles.

      Other than that, you got me... but I'm an old dog like Mr. Muskrat and tend to use them, at least in my main programs. (I manage to avoid them in modules though.)

      -sauoq
      "My two cents aren't worth a dime.";
      
      One more reason TO use the variable method:

      Better error messages, as you can get the filename in messages using the following:

      my $f = "/etc/hosts"; open($f, $f); readit($f); sub readit { my $h = shift; print while(<$h>); warn; }
      The result:
      last line of output is:
      Warning: something's wrong at ./t25.pl line 11, </etc/hosts> line 12.


      --Bob Niederman, http://bob-n.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-23 21:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found