Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by talexb (Chancellor)
on Oct 19, 2018 at 21:42 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1224361]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-23 17:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found