if (! open my $in_fh, '<', $in ) {
# ^^ <- HERE
die "Can't open '$in': $!";
}
####
if (! open my $fh, '<', $file){
die $!;
}
# file handle already closed if you try to access here
##
##
{
open my $fh, '<', $file or die $!;
# can use the fh here
}
# but not here, fh auto-closed in the block
##
##
my $fh;
if (! open $fh, '<', $file){
die $!;
}
# you can successfully use fh here...
# it'll only close if you "close $fh or die $!;", or when the file (program) exits
# the above example has the same effect of doing the below example, but this is
# easier as you don't have a bunch of variables declared at the top of your file.
# the entire idea is to keep variables declared, defined as close to
# the place you intend to use them
open my $fh, '<', $file or die $!;