Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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

by tye (Sage)
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        

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://929880]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2017-01-20 10:56 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (174 votes). Check out past polls.