in reply to Devious destructor

That's good defensive programming. If it didn't look so stupid, I'd put local $_; as the first line of every one of my subs. (For some moonlighting I might do, I will do that.) I never thought of doing that for $! and $?, neither of which I use very much. *shrugs*

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Re: Devious destructor
by Juerd (Abbot) on Mar 13, 2002 at 15:29 UTC

    That's good defensive programming

    It sure is!
    Defensive programming can bite you, though. Kane, one of the Rotterdam Perl Mongers once told the story about what happens if you localize $@ in a BEGIN block. By programming defensively, he ran into a bug in perl :)

    perl -e'BEGIN { local $@; print "a"; die "b"; print "c"; } print "d";'
    It turns out that the program doesn't die, and it doesn't display "b" (and not "at -e line 1"). The snippet above prints "ad". If it didn't localize $@, it would print:
    b at -e line 1. BEGIN failed--compilation aborted at -e line 1.
    Scary, huh?

    If you localize special variables, look out for bugs, and if you find any, report them!

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk