Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Parsing Multiple Lines.

by NetWallah (Canon)
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.

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,

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://355822]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2018-01-21 07:46 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (227 votes). Check out past polls.