Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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>;
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://761121]
[choroba]: which usually means its input wasn't handled correctly
[Corion]: choroba: Yeah, I think that would be the good solution
[LanX]: I suspect the first string which comes from the DB ...
[LanX]: ... but this part is already in production for a year now
[Corion]: LanX: The "good" approach here would be to use the appropriate DBI parameters to make the driver decode strings properly. But that will have a ripple-on effect of messing up all the places where manual decoding happens ;)
[LanX]: which means albeit being broken UTF8 it'll be handled correctly
[LanX]: and the problem only occurs since we changed the emails to base64
[LanX]: my main problem will be to cnvince my colleagues that our productive code is broken oO ... so in the end I will just make a workaround :-/
LanX hates UTF8 for causing knots in his brain and stomach

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2017-01-16 14:02 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (150 votes). Check out past polls.