I have a program which accepts a perl data structure which is intended to be a Storable scalar. Is there a way to test if the scalar is a valid Storable object, without dying if it isn’t?
For instance, if I do:
use Storable qw(freeze thaw);
my $ref = thaw("lol_not_storable")
I get back “Storable binary image v54.111 more recent than I am (v2.8) at /usr/local/lib/perl/5.12.4/Storable.pm line 420, at test.pl line 5”
I would like to figure out if it is possible to cleanly handle these exceptions without eval. Is it possible without rewriting the Storable Perl Module?
is not the same thing as
in that Perl has ample chance to parse the first, but waits to parse the second. Observe, the below is a compile error:
Whereas
eval '$i++'wouldn’t be. I think most of the discouragement you have heard aboutevalis more of the latter type and not of the former. The latter evaluates a string as code, the former mainly tells Perl “don’t die.”Here’s the string version:
Outputs:
The code still fails to compile, but only when it’s
eval-ed, and only has effect when I check$@, which reads: