Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: First attempt at bringing in file for input/output

by talexb (Canon)
on Oct 19, 2018 at 21:42 UTC ( #1224361=note: print w/replies, xml ) Need Help??


in reply to First attempt at bringing in file for input/output

I'll just jump in and promote the use of autodie, a module that takes care of catching file open errors. For quite a while I wrote file operations in C like this:

FILE *pif; pif = fopen ( $filename, 'r' ); if ( pif == NULL ) { /* Problem opening file.. */ } .. fclose ( pif );
When I started writing Perl, I did the same kind of thing ..
open ( my $in_fh, '<', $filename ) or die "Unable to open $filename for read: $!"; .. close ( $in_fh );
With autodie, that can be simplified to
use autodie; open ( my $in_fh, '<', $filename ); .. close ( $in_fh );
I think that's pretty handy.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2019-07-22 09:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (12 votes). Check out past polls.

    Notices?