my $var = LoadFile($fh) or warn/die "MESSAGE";
####
YAML Error: Inconsistent indentation level
Code: YAML_PARSE_ERR_INCONSISTENT_INDENTATION
Line: 21
Document: 1
at /usr/share/perl5/YAML/Loader.pm line 719
####
#!/usr/bin/env perl
use strict;
use Getopt::Long;
use YAML qw(LoadFile);
use Data::Dumper;
my $file;
GetOptions (
"file=s" => \$file);
if ( $file ) {
$SIG{__DIE__} = sub { die("My error: ", @_); };
$SIG{__WARN__} = sub { warn("My warning: ", @_); };
open my $fh, '<', $file
or die "Cannot open target file\n"; #THIS ERROR IS CATCHABLE
my $config = LoadFile($fh)
or warn("YAML parsing error\n"); #CANNOT CATCH ERROR
#or warn "YAML parsing error\n"; #CANNOT CATCH ERROR
print Dumper(\$config), "\n";
} else {
die "Syntax: $0 [-f,--file] [YAML_FILE]";
}