Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: A Few Questions About IO::File (be explicit)

by Anonymous Monk
on Mar 18, 2013 at 11:04 UTC ( #1024075=note: print w/replies, xml ) Need Help??

in reply to A Few Questions About IO::File

You can't go wrong with being explicit (close), it really depends on the rest of the code :)

undef can work, provided there is only ever a single reference / copy of filehandle, but won't close if reference count goes up  my $copy = $fh; close will always close -- explicit is good (q:gimme some? a: some what? q: that over there; q: to the left; q: lefter; :)

But if you write in narrow scopes

if( open my($fh) ... ){ 1 2 3 4 5 }

implicit undef can work, as can explicit undef, as can explicit close

Which is better?  print $fh $str or die $!; close $fh or die $! ? use autodie ? Whatever fits?

It's very convenient, but this isn't mentioned anywhere in the doc and I'm not sure whether this has any negative side effects.

Often the doc is a start of a reading list, not just Ctrl+F for "close" :)

IO::File -> IO::File inherits from IO::Handle and IO::Seekable -> SEE ALSO perlfunc, I/O Operators in perlop, IO::Handle, IO::Seekable, IO::Dir

IO::Handle lists the close method

the close function which you can also use is listed at perlfunc#close , #Input and output functions, close

Replies are listed 'Best First'.
Re^2: A Few Questions About IO::File (be explicit)
by Anonymous Monk on Mar 18, 2013 at 11:06 UTC
    :) Ha, getlines is also documented in IO::Handle
Re^2: A Few Questions About IO::File (be explicit)
by rpetrelli (Novice) on Mar 18, 2013 at 11:19 UTC

    See my reply to hdb. I already read the IO::Handle (oops just realized I had a typo there, how do you edit your post anyway?), but what perplexes me is the chaining methods part.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2018-12-15 09:40 GMT
Find Nodes?
    Voting Booth?
    How many stories does it take before you've heard them all?

    Results (69 votes). Check out past polls.