Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Parsing Multiple Lines.

by NetWallah (Canon)
on May 24, 2004 at 03:59 UTC ( [id://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.

Replies are listed 'Best First'.
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

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-24 06:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found