Sorry but your ideas are not trivial or easy to grasp, so I have to go little by little. =)
I find the desired short cut behaviour to catch undef even more problematic than the rest.
I'd rather prefer a catch_undef { BLOCK } command, because the block would be explicit about what is caught without much explanation.
This can be emulated (at least) with
my $h_b = {};
my $x = eval {
use warnings FATAL => 'uninitialized' ;
$h_b->{velocity}." mph";
} // 'unknown';
print $x;
I tried to construct some syntactic sugar
sub catch_undef (&) {
my $code_ref = shift;
eval {
use warnings FATAL => 'uninitialized' ;
$code_ref->()
};
}
but I'm running into two problems:
1) Obviously pragmas are lexically scoped, I seem to remember there are some obscure tricks to manipulate the warning flags of a coderef (something with $^H ?) but I'm too lazy at the moment.
2) seems to be a bug in the parser, because I get a weird syntax error for
catch_undef { $ref->{velocity} .'mph' } // "unknown";
Too many arguments for main::catch_undef at /tmp/tst.pl line 29, near "// "unknown""
using || instead solves the parsing problem (but not the task)
|