rovf has asked for the wisdom of the Perl Monks concerning the following question:

I'm not asking for a solution this time (because I've solved the problem), but for an explanation - I would like to know why my solution worked. This was the original problem:

We had some code which basically looked like this:

# This is file P.pm package P; use strict; use warnings; use PX; .... eval { PX::myfunc(...); }; if($@) { print "Exception!\n"; } .... # This is file PX.pm package PX; use strict; use warnings; sub myfunc { ... print("let's do it\n"); foreach my $c (@{ $foo->{bar}->{baz} }) { oink_oink_oink(); } print "I've done it\n"; }
Due to a mistake, $foo was set up in a way that the expression in the foreach produced a "Pseudo Hash Deprecated" error. I would have expected to see the output
let's do it Exception!
but instead I was seeing
let's do it Pseudo hashes are deprecated at....
and the program terminated. I solved this by changing PX.pm so that the warnings Pragma in PX.pm reads
use warnings FATAL => qw(all);
I saw the expected output. This puzzles me for two reason:

First, I understand that using a pseudo hash results in a run-time error, which means an exception should be generated. Since the calling program uses eval, the exception should have been caught here.

Second, the modified pragma just means that "warnings are turned into an exception". Since "Pseudo hashes are deprecated" is not a warning (after all, the program aborted afterwards), it should not be affected by warnings FATAL=>'all'. Could someone enlighten me here? This was run on ActiveState Perl 5.8.8.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re: use warnings; and deprecated Pseudo hashes
by ambrus (Abbot) on Aug 27, 2009 at 13:35 UTC

    Pseudo-hashes are depreciated in perl 5.8 but they are still supported so "Pseudo hashes are depreceated" is only a warning. On the other hand, pseudohashes are completely unsupported in perl 5.10, so there you'd indeed get an error with the message "Not a HASH reference". Just try this standalone test:

    perl -we 'warn ${[{"a",1},"foo"]}{"a"}'
    In perl 5.8 you get a warnings but the right result:
    Pseudo-hashes are deprecated at -e line 1. foo at -e line 1.
    whereas perl 5.10 dies.
Re: use warnings; and deprecated Pseudo hashes
by JavaFan (Canon) on Aug 27, 2009 at 13:36 UTC
    Eh, "Pseudo hashes are deprecated" IS a warning. Which explains both why the program continues the first time, and gives an exception after changing warnings into fatals.
      Pseudo hashes are deprecated" IS a warning.

      This would explain why no exception has been thrown originally, so the crash must have occured later (as a consequence of the error), before the program had a chance to output something. This makes sense to me - thanks a lot.

      -- 
      Ronald Fischer <ynnor@mm.st>