Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Devious destructor

by dragonchild (Archbishop)
on Mar 12, 2002 at 19:13 UTC ( [id://151196]=note: print w/replies, xml ) Need Help??


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
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://151196]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-23 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found