http://www.perlmonks.org?node_id=1179359


in reply to Re^4: Multiple actions triggered by failure to open a file
in thread Multiple actions triggered by failure to open a file

I find that often I do want a lexically scoped file handle. Also, I often find that failure to open a file is a perfectly good reason to have both if and else blocks.

my $logfile = './testlogfile.txt'; if ( open my $log_FH, '>', $logfile ) { do_stuff_and_write_info_to_log_about_it( $log_FH ); } else { print "Failure to open log file.\n"; die "Failure to open log file $logfile for writing.: $!\n"; }