Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Parsing Multiple Lines.

by NetWallah (Abbot)
on May 24, 2004 at 03:59 UTC ( #355822=note: print w/ replies, xml ) Need Help??


in reply to Parsing Multiple Lines.

You have declared the filehandle used in "open" (my $fh) - That makes $fh a Symbolic reference to the file handle, and I don't believe you are trying to do that - more likely, this is a result of misunderstanding the statement in the doc:
If FILEHANDLE is an undefined lexical (my) variable the variable is assigned a reference to a new anonymous filehandle....

Juse use an UNDEFINED name like FH (No dollar), and you'll be OK.
Update: OK - seems like I need to re-read the docs myself. See notes below.

Offense, like beauty, is in the eye of the beholder, and a fantasy.
By guaranteeing freedom of expression, the First Amendment also guarntees offense.


Comment on Re: Parsing Multiple Lines.
Re: Re: Parsing Multiple Lines.
by Somni (Friar) on May 24, 2004 at 05:16 UTC

    Er, no, open(my $fh, "...") is correct usage. $fh is autovivified into an actual filehandle (not just a symbolic reference). It is the preferred method for opening a filehandle without clobbering an existing one. The excerpt you are referring to does mean an undefined scalar variable ($fh), not a bareword (FH).

    perldoc perlopentut provides several examples of this in the Indirect Filehandles section.

Re: Re: Parsing Multiple Lines.
by Zaxo (Archbishop) on May 24, 2004 at 05:21 UTC

    Bzzzt. Not a symref.

    $ perl -e'my $fh;open($fh, "< foo") or die $!; print "$fh"' GLOB(0x804b3f8)$
    Nothing wrong with OP's lexical filehandle. It is good practice to localize a global handle such as you recommend within some scope. Then you don't need to worry about name uniqueness.

    After Compline,
    Zaxo

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (13)
As of 2015-07-06 22:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (83 votes), past polls