当我传递一个无效的文件名时,为什么这个脚本继续运行而不死?
#!/usr/bin/env perl
use warnings;
use 5.12.0;
use Getopt::Long qw(GetOptions :config bundling);
sub help {
say "no help text";
}
sub read_config {
my $file = shift;
open my $fh, '<', $file or die $!;
say <$fh>;
close $fh;
}
sub helpers_dispatch_table {
return {
'h_help' => \&help,
'r_read' => \&read_config,
};
}
my $file_conf = 'does_not_exist.txt';
my $helpers = helpers_dispatch_table();
GetOptions (
'h|help' => sub { $helpers->{h_help}(); exit; },
'r|read' => sub { $helpers->{r_read}( $file_conf ); exit },
);
say "Hello, World!\n" x 5;