Beefy Boxes and Bandwidth Generously Provided by pair Networks Ovid
The stupid question is the question not asked
 
PerlMonks  

Re^4: Inotify2 + AnyEvent (naked code ref)

by tye (Cardinal)
on Oct 05, 2011 at 21:05 UTC ( #929880=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Inotify2 + AnyEvent (naked code ref)
in thread Inotify2 + AnyEvent

I'm not going to install Tk at the moment. But, \&callback does not call callback() (it just provides a code ref):

$ perl -le 'sub callback { die "called( @_ )!" } print \&callback' CODE(0x219b4c0) $ perl -le 'sub callback { die "called( @_ )!" } print \&callback("ar +g")' called( arg )! at -e line 1. $

The Tk::Button documentation (see also Tk::callbacks) implies that -command => $codeRef will not immediately call the referenced sub.

There certainly could be other reasons for that usage to cause "pre-mature exit and crash". For example, -command => \&callback, time, would likely "crash".

I see plenty of evidence to suggest that it will not cause callback() to be called at button-creation time and no details suggesting that you have enough evidence to support that one part of your claim.

- tye        


Comment on Re^4: Inotify2 + AnyEvent (naked code ref)
Select or Download Code
Re^5: Inotify2 + AnyEvent (naked code ref)
by zentara (Archbishop) on Oct 06, 2011 at 10:06 UTC
    I'm not going to install Tk at the moment.

    Ok, thanks for explaining. It's the () that causes premature exiting.

    #!/usr/bin/perl use warnings; use strict; use Tk; my $mw = new MainWindow; $mw->geometry("400x200"); my $button = $mw->Button(-text => "Sub test exit", -command => \&callback(), # exits prematurely # -command => \&callback, # works ok )->pack(); MainLoop; sub callback{ print "exiting\n"; Tk::exit; } __END__

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      $ perl -MO=Deparse -e " $foo = \&bar " $foo = \&bar; -e syntax OK $ perl -MO=Deparse -e " $foo = \&bar() " $foo = \(&bar()); -e syntax OK

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (14)
As of 2014-04-17 13:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (447 votes), past polls