Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Overloading '{}' or 'sub'

by jasonk (Parson)
on Jan 01, 2009 at 20:06 UTC ( #733661=note: print w/replies, xml ) Need Help??


in reply to Overloading '{}' or 'sub'

See Scope::Guard, which is designed to do exactly that, you create it with a subroutine to run when it goes out of scope...

use strict; use warnings; use Scope::Guard; sub foo { my $blah = shift; my $sg = Scope::Guard->new( sub { print "This runs at the end of the scope\n"; } ); print "Doing some other stuff now...\n"; }

www.jasonkohles.com
We're not surrounded, we're in a target-rich environment!

Replies are listed 'Best First'.
Re^2: Overloading '{}' or 'sub'
by wdef2 (Acolyte) on Jan 01, 2009 at 22:52 UTC
    Wasn't operator overloading designed by Satan for evil C++ programmers to torture each other in the hell that they have created for themselves. Or something?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://733661]
help
Chatterbox?
[karlgoethebier]: Unne hip unne hop unne schoppe inne kopp...
[1nickt]: kgb not quite as simple as ... and ...; are interchangeable. There are edge cases, shown in perlsyn.
[1nickt]: Hm well actually I guess it's not the trailing semi-colon that's at issue there, it's disambiguation between the ellipsis and the binary flip-flop
[1nickt]: Although the example given does not produce an error as stated, on my perl.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2017-11-18 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?