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 15:06 UTC | |
|
Re^2: A Few Questions About IO::File (be explicit)
by rpetrelli (Novice) on Mar 18, 2013 at 15:19 UTC |