use strict;
#use diagnostics;
use JSON qw(decode_json encode_json);
use Try::Tiny;
use warnings;
$SIG{__DIE__} = sub {
my $item = shift;
my $lasterr = "";
$lasterr = $@ if (defined($@));
chomp ($item);
print STDERR "DIE ERROR: $item : $lasterr\n";
local $! = 2;
exit $!;
}; # end SIG_DIE
sub write_mets {
my $collref;
# Read first line of test file
my $file = "data1";
open (my $f, "<", $file) || die "Error opening: $!";
my $json1 = <$f>;
close ($f);
try {
$collref = decode_json ($json1);
print STDOUT "Read file $file\n";
} catch {
print STDERR "Error decoding data from $file $@ \n";
};
}
write_mets();
1;
####
$ perl S2.pl
DIE ERROR: garbage after JSON object, at character offset 7413 (before "n\n") at S2.pl line 30. :
####
$ perl S2.pl
Error decoding data from data1