Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: FileHandle: undef vs close

by Crackers2 (Parson)
on Apr 30, 2009 at 18:03 UTC ( #761121=note: print w/replies, xml ) Need Help??


in reply to FileHandle: undef vs close

They're not 100% identical, as the following code shows:
use warnings; use FileHandle; $fh = new FileHandle "file", "r"; if (defined $fh) { print <$fh>; undef $fh; # automatically closes the file } $fh2 = new FileHandle "file", "r"; if (defined $fh2) { print <$fh2>; close $fh2; # automatically closes the file } print <$fh>; print <$fh2>;
Output:
Use of uninitialized value in <HANDLE> at t line 16. readline() on unopened filehandle at t line 16. readline() on closed filehandle GEN1 at t line 17.

Doing a close seems to maintain some information about the filehandle, and the variable stays defined. Doing an undef unsurprisingly undefs the variable, so you get a slightly different warning, and an extra one about it being udnefined.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://761121]
help
Chatterbox?
[LanX]: auto-subtitles in YT are entertaining: "fuehrer" instead of fewer, "jews" instead of juice ...
Discipulus never noticed there was subtitles... can I call them with &subtitle or is too much perl 4?
[LanX]: YT=youtube
[Discipulus]: ;=) yes i'm not SO dumb
[LanX]: SO=StackOverflow

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2017-06-23 16:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (552 votes). Check out past polls.