develooper Front page | perl.perl5.porters | Postings from March 2008

Re: local $@ has an unwanted side effect

Thread Previous
From:
Dr.Ruud
Date:
March 22, 2008 04:17
Subject:
Re: local $@ has an unwanted side effect
Message ID:
20080322111720.8457.qmail@lists.develooper.com
chromatic schreef:
> Dr.Ruud:
>> David Nicol:

>>> So should we introduce an automatic localization of $@ before
>>> destruction?
> 
>> Just leave $@ as is, and introduce @@.
> 
> Rubyometer++
> 
> Wait, is this the Perl *5* list?  Sorry!

<g> 

#!/usr/bin/perl
# dieritis-@@.pl

use strict;
use warnings;
use Time::HiRes qw/time/;
use Data::Dumper;

sub Q::DESTROY {
    $@ and push @@, [ $@, time, $$ ];
    eval {
        die "died in INNER eval";
    };
}

push @@, [ "__start", time, $$ ];

eval {
    my $x = bless [], "Q";
    die "died in OUTER eval";
};
$@ and push @@, [ $@, time, $$ ];

chomp $_->[0] for @@;
print Dumper(\@@);


Output:

$VAR1 = [
          [
            '__start',
            '1206184429.74886',
            22961
          ],
          [
            'died in OUTER eval at ./dieritis-@@.pl line 20.',
            '1206184429.74889',
            22961
          ],
          [
            'died in INNER eval at ./dieritis-@@.pl line 12.',
            '1206184429.7489',
            22961
          ]
        ];

-- 
Affijn, Ruud

"Gewoon is een tijger."

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About