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