Why doesn't this script work
User:
mcholste
Date: 7/15/2011 3:46 pm
Date: 7/15/2011 3:46 pm
Views: 616
Rating: 0
Rating: 0
#!/usr/bin/perl
use strict;
use Data::Dumper;
use AnyEvent;
use EV;
# This works as expected
my $w1; $w1 = AnyEvent->timer(after => 1, cb => sub { warn('HERE1'); });
my ($w2, $w3);
# Neither of these wait for EV::loop, program exists after 1 second
instead of running the 2 and 3 second watchers. Why does the
subroutine matter?
run2($w2);
run3($w3);
EV::loop;
sub run2 {
my $w = shift;
$w = AnyEvent->timer(after => 2, cb => sub { warn('HERE2'); });
warn 'created 2';
}
sub run3 {
my $w = shift;
$w = AnyEvent->timer(after => 3, cb => sub { warn('HERE3'); });
warn 'created 3';
}
use strict;
use Data::Dumper;
use AnyEvent;
use EV;
# This works as expected
my $w1; $w1 = AnyEvent->timer(after => 1, cb => sub { warn('HERE1'); });
my ($w2, $w3);
# Neither of these wait for EV::loop, program exists after 1 second
instead of running the 2 and 3 second watchers. Why does the
subroutine matter?
run2($w2);
run3($w3);
EV::loop;
sub run2 {
my $w = shift;
$w = AnyEvent->timer(after => 2, cb => sub { warn('HERE2'); });
warn 'created 2';
}
sub run3 {
my $w = shift;
$w = AnyEvent->timer(after => 3, cb => sub { warn('HERE3'); });
warn 'created 3';
}
Re: Why doesn't this script work
User:
afbach
Date: 7/15/2011 4:09 pm
Date: 7/15/2011 4:09 pm
Views: 0
Rating: 0
Rating: 0
On Fri, Jul 15, 2011 at 3:46 PM, wrote:
> mcholste wrote:
> my ($w2, $w3);
>
> # Neither of these wait for EV::loop, program exists after 1 second
> instead of running the 2 and 3 second watchers. Why does the
> subroutine matter?
> run2($w2);
> run3($w3);
Was the idea here that you'd end up w/ the local $w2 and $w3 holding a
reference to the new, sub created AnyEvents? 'cause this is like:
run2(undef);
run3(undef);
You could try
run2(\$w2);
sub run2
{
my $w = shift; # now has/is a ref to $w2?
--
a
Andy Bach,
afbach@gmail.com
608 658-1890 cell
608 261-5738 wk
> mcholste wrote:
> my ($w2, $w3);
>
> # Neither of these wait for EV::loop, program exists after 1 second
> instead of running the 2 and 3 second watchers. Why does the
> subroutine matter?
> run2($w2);
> run3($w3);
Was the idea here that you'd end up w/ the local $w2 and $w3 holding a
reference to the new, sub created AnyEvents? 'cause this is like:
run2(undef);
run3(undef);
You could try
run2(\$w2);
sub run2
{
my $w = shift; # now has/is a ref to $w2?
--
a
Andy Bach,
afbach@gmail.com
608 658-1890 cell
608 261-5738 wk
Re: Why doesn't this script work
User:
miner
Date: 7/15/2011 4:23 pm
Date: 7/15/2011 4:23 pm
Views: 0
Rating: 0
Rating: 0
On 7/15/11 4:09 PM, afbach@gmail.com wrote:
> You could try
> run2(\$w2);
>
> sub run2
> {
> my $w = shift; # now has/is a ref to $w2?
Yup.
You'll need to actually use it as $$w, though, as in:
$$w = AnyEvent->timer(...)
jon
--
.Jonathan J. Miner----------------------------------------------------.
| jon@jjminer.org | photos - http://photos.jjminer.org/ |
| | R.A.W. #1629 - http://www.reggaeambassadors.org |
| | LOCS Webmaster - http://www.locs-buffett.org |
| jabber/gchat: camrycurbhopper@gmail.com AIM: camrycurbhopper |
`---------------------------------------------------------------------'
"We don't have a town drunk... We all take turns!"
-- James Slater, "Key West Address"
> You could try
> run2(\$w2);
>
> sub run2
> {
> my $w = shift; # now has/is a ref to $w2?
Yup.
You'll need to actually use it as $$w, though, as in:
$$w = AnyEvent->timer(...)
jon
--
.Jonathan J. Miner----------------------------------------------------.
| jon@jjminer.org | photos - http://photos.jjminer.org/ |
| | R.A.W. #1629 - http://www.reggaeambassadors.org |
| | LOCS Webmaster - http://www.locs-buffett.org |
| jabber/gchat: camrycurbhopper@gmail.com AIM: camrycurbhopper |
`---------------------------------------------------------------------'
"We don't have a town drunk... We all take turns!"
-- James Slater, "Key West Address"
Re: Why doesn't this script work
User:
lecar_red
Date: 7/15/2011 4:52 pm
Date: 7/15/2011 4:52 pm
Views: 0
Rating: 0
Rating: 0
Hello,
It is about half way there with passing in the variable by reference but then you need to dereference it to store the value in the right spot.
<snip>
run2( \$w2 );
run3( \$w3 );
EV::loop;
sub run2 {
my $w = shift;
$$w = AnyEvent->timer(after => 2, cb => sub { warn('HERE2'); });
warn 'created 2';
}
sub run3 {
my $w = shift;
$$w = AnyEvent->timer(after => 3, cb => sub { warn('HERE3'); });
warn 'created 3';
}
Might be easier to just return back the object from the constructor... But I'm guessing you might be using this as a simplified case.
Good luck,
Lee
From: "afbach@gmail.com" <afbach@gmail.com>
To: lecar_red@yahoo.com
Sent: Friday, July 15, 2011 4:09 PM
Subject: [MadTalk] Re: Why doesn't this script work afbach wrote:On Fri, Jul 15, 2011 at 3:46 PM, wrote:
> mcholste wrote:
> my ($w2, $w3);
>
> # Neither of these wait for EV::loop, program exists after 1 second
> instead of running the 2 and 3 second watchers. Why does the
> subroutine matter?
> run2($w2);
> run3($w3);
Was the idea here that you'd end up w/ the local $w2 and $w3 holding a
reference to the new, sub created AnyEvents? 'cause this is like:
run2(undef);
run3(undef);
You could try
run2(\$w2);
sub run2
{
my $w = shift; # now has/is a ref to $w2?
Re: Why doesn't this script work
User:
hoelzro
Date: 7/15/2011 4:16 pm
Date: 7/15/2011 4:16 pm
Views: 100
Rating: 0
Rating: 0
You're assigning your watcher objects to a local variable in run2/run3,
so they get destroyed when those functions return. Try this:
my $w2 = run2();
or this:
sub run2 {
my ( $wref ) = @_;
$$wref = AnyEvent->timer(...);
}
run2(\$w2);
wrote:
> mcholste wrote:
> #!/usr/bin/perl
> use strict;
> use Data::Dumper;
> use AnyEvent;
> use EV;
>
> # This works as expected
> my $w1; $w1 = AnyEvent->timer(after => 1, cb => sub
> { warn('HERE1'); });
>
> my ($w2, $w3);
>
> # Neither of these wait for EV::loop, program exists after 1 second
> instead of running the 2 and 3 second watchers. Why does the
> subroutine matter?
> run2($w2);
> run3($w3);
> EV::loop;
>
> sub run2 {
> my $w = shift;
> $w = AnyEvent->timer(after => 2, cb => sub { warn('HERE2'); });
> warn 'created 2';
> }
>
> sub run3 {
> my $w = shift;
> $w = AnyEvent->timer(after => 3, cb => sub { warn('HERE3'); });
> warn 'created 3';
> }
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
so they get destroyed when those functions return. Try this:
my $w2 = run2();
or this:
sub run2 {
my ( $wref ) = @_;
$$wref = AnyEvent->timer(...);
}
run2(\$w2);
wrote:
> mcholste wrote:
> #!/usr/bin/perl
> use strict;
> use Data::Dumper;
> use AnyEvent;
> use EV;
>
> # This works as expected
> my $w1; $w1 = AnyEvent->timer(after => 1, cb => sub
> { warn('HERE1'); });
>
> my ($w2, $w3);
>
> # Neither of these wait for EV::loop, program exists after 1 second
> instead of running the 2 and 3 second watchers. Why does the
> subroutine matter?
> run2($w2);
> run3($w3);
> EV::loop;
>
> sub run2 {
> my $w = shift;
> $w = AnyEvent->timer(after => 2, cb => sub { warn('HERE2'); });
> warn 'created 2';
> }
>
> sub run3 {
> my $w = shift;
> $w = AnyEvent->timer(after => 3, cb => sub { warn('HERE3'); });
> warn 'created 3';
> }
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
Re: Why doesn't this script work
User:
miner
Date: 7/15/2011 4:26 pm
Date: 7/15/2011 4:26 pm
Views: 101
Rating: 0
Rating: 0
This is true. Returning the object is much more elegant.
jon
On 7/15/11 4:16 PM, rob@hoelz.ro wrote:
jon
On 7/15/11 4:16 PM, rob@hoelz.ro wrote:
hoelzro wrote:
You're assigning your watcher objects to a local variable in run2/run3,
so they get destroyed when those functions return. Try this:
my $w2 = run2();
or this:
sub run2 {
my ( $wref ) = @_;
$$wref = AnyEvent->timer(...);
}
run2(\$w2);
wrote:
> mcholste wrote:
> #!/usr/bin/perl
> use strict;
> use Data::Dumper;
> use AnyEvent;
> use EV;
>
> # This works as expected
> my $w1; $w1 = AnyEvent->timer(after => 1, cb => sub
> { warn('HERE1'); });
>
> my ($w2, $w3);
>
> # Neither of these wait for EV::loop, program exists after 1 second
> instead of running the 2 and 3 second watchers. Why does the
> subroutine matter?
> run2($w2);
> run3($w3);
> EV::loop;
>
> sub run2 {
> my $w = shift;
> $w = AnyEvent->timer(after => 2, cb => sub { warn('HERE2'); });
> warn 'created 2';
> }
>
> sub run3 {
> my $w = shift;
> $w = AnyEvent->timer(after => 3, cb => sub { warn('HERE3'); });
> warn 'created 3';
> }
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org
-- .Jonathan J. Miner----------------------------------------------------. | jon@jjminer.org | photos - http://photos.jjminer.org/ | | | R.A.W. #1629 - http://www.reggaeambassadors.org | | | LOCS Webmaster - http://www.locs-buffett.org | | jabber/gchat: camrycurbhopper@gmail.com AIM: camrycurbhopper | `---------------------------------------------------------------------' "We don't have a town drunk... We all take turns!" -- James Slater, "Key West Address"
Re: Why doesn't this script work
User:
esayward
Date: 7/15/2011 5:29 pm
Date: 7/15/2011 5:29 pm
Views: 0
Rating: 0
Rating: 0
so funny.. I was about to reply and there was
already 4 returns...
----- Original Message -----From: jon@jjminer.orgTo: admin@wisbin.comSent: Friday, July 15, 2011 4:26 PMSubject: [MadTalk] Re: Why doesn't this script workminer wrote:
This is true. Returning the object is much more elegant.
jon
On 7/15/11 4:16 PM, rob@hoelz.ro wrote:hoelzro wrote:
You're assigning your watcher objects to a local variable in run2/run3,
so they get destroyed when those functions return. Try this:
my $w2 = run2();
or this:
sub run2 {
my ( $wref ) = @_;
$$wref = AnyEvent->timer(...);
}
run2(\$w2);
wrote:
> mcholste wrote:
> #!/usr/bin/perl
> use strict;
> use Data::Dumper;
> use AnyEvent;
> use EV;
>
> # This works as expected
> my $w1; $w1 = AnyEvent->timer(after => 1, cb => sub
> { warn('HERE1'); });
>
> my ($w2, $w3);
>
> # Neither of these wait for EV::loop, program exists after 1 second
> instead of running the 2 and 3 second watchers. Why does the
> subroutine matter?
> run2($w2);
> run3($w3);
> EV::loop;
>
> sub run2 {
> my $w = shift;
> $w = AnyEvent->timer(after => 2, cb => sub { warn('HERE2'); });
> warn 'created 2';
> }
>
> sub run3 {
> my $w = shift;
> $w = AnyEvent->timer(after => 3, cb => sub { warn('HERE3'); });
> warn 'created 3';
> }
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org-- .Jonathan J. Miner----------------------------------------------------. | jon@jjminer.org | photos - http://photos.jjminer.org/ | | | R.A.W. #1629 - http://www.reggaeambassadors.org | | | LOCS Webmaster - http://www.locs-buffett.org | | jabber/gchat: camrycurbhopper@gmail.com AIM: camrycurbhopper | `---------------------------------------------------------------------' "We don't have a town drunk... We all take turns!" -- James Slater, "Key West Address"
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org
Re: Why doesn't this script work
User:
mcholste
Date: 7/15/2011 5:57 pm
Date: 7/15/2011 5:57 pm
Views: 93
Rating: 0
Rating: 0
I like to serve up some softballs to make you all feel good going into
the weekend!
On Fri, Jul 15, 2011 at 5:29 PM, wrote:
> esayward wrote:
>
> so funny.. I was about to reply and there was already 4 returns...
>
> ----- Original Message -----
> From: jon@jjminer.org
> To: admin@wisbin.com
> Sent: Friday, July 15, 2011 4:26 PM
> Subject: [MadTalk] Re: Why doesn't this script work
>
> miner wrote:
>
> This is true. Returning the object is much more elegant.
>
> jon
>
> On 7/15/11 4:16 PM, rob@hoelz.ro wrote:
>
> hoelzro wrote:
>
> You're assigning your watcher objects to a local variable in run2/run3,
> so they get destroyed when those functions return. Try this:
>
> my $w2 = run2();
>
> or this:
>
> sub run2 {
> my ( $wref ) = @_;
>
> $$wref = AnyEvent->timer(...);
> }
> run2(\$w2);
>
> wrote:
>
>> mcholste wrote:
>> #!/usr/bin/perl
>> use strict;
>> use Data::Dumper;
>> use AnyEvent;
>> use EV;
>>
>> # This works as expected
>> my $w1; $w1 = AnyEvent->timer(after => 1, cb => sub
>> { warn('HERE1'); });
>>
>> my ($w2, $w3);
>>
>> # Neither of these wait for EV::loop, program exists after 1 second
>> instead of running the 2 and 3 second watchers. Why does the
>> subroutine matter?
>> run2($w2);
>> run3($w3);
>> EV::loop;
>>
>> sub run2 {
>> my $w = shift;
>> $w = AnyEvent->timer(after => 2, cb => sub { warn('HERE2'); });
>> warn 'created 2';
>> }
>>
>> sub run3 {
>> my $w = shift;
>> $w = AnyEvent->timer(after => 3, cb => sub { warn('HERE3'); });
>> warn 'created 3';
>> }
>>
>> View Online
>>
>> Madison Area Perl Mongers - MadMongers
>> http://www.madmongers.org
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
> --
> .Jonathan J. Miner----------------------------------------------------.
> | jon@jjminer.org | photos - http://photos.jjminer.org/ |
> | | R.A.W. #1629 - http://www.reggaeambassadors.org |
> | | LOCS Webmaster - http://www.locs-buffett.org |
> | jabber/gchat: camrycurbhopper@gmail.com AIM: camrycurbhopper |
> `---------------------------------------------------------------------'
>
> "We don't have a town drunk... We all take turns!"
> -- James Slater, "Key West Address"
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
the weekend!
On Fri, Jul 15, 2011 at 5:29 PM, wrote:
> esayward wrote:
>
> so funny.. I was about to reply and there was already 4 returns...
>
> ----- Original Message -----
> From: jon@jjminer.org
> To: admin@wisbin.com
> Sent: Friday, July 15, 2011 4:26 PM
> Subject: [MadTalk] Re: Why doesn't this script work
>
> miner wrote:
>
> This is true. Returning the object is much more elegant.
>
> jon
>
> On 7/15/11 4:16 PM, rob@hoelz.ro wrote:
>
> hoelzro wrote:
>
> You're assigning your watcher objects to a local variable in run2/run3,
> so they get destroyed when those functions return. Try this:
>
> my $w2 = run2();
>
> or this:
>
> sub run2 {
> my ( $wref ) = @_;
>
> $$wref = AnyEvent->timer(...);
> }
> run2(\$w2);
>
> wrote:
>
>> mcholste wrote:
>> #!/usr/bin/perl
>> use strict;
>> use Data::Dumper;
>> use AnyEvent;
>> use EV;
>>
>> # This works as expected
>> my $w1; $w1 = AnyEvent->timer(after => 1, cb => sub
>> { warn('HERE1'); });
>>
>> my ($w2, $w3);
>>
>> # Neither of these wait for EV::loop, program exists after 1 second
>> instead of running the 2 and 3 second watchers. Why does the
>> subroutine matter?
>> run2($w2);
>> run3($w3);
>> EV::loop;
>>
>> sub run2 {
>> my $w = shift;
>> $w = AnyEvent->timer(after => 2, cb => sub { warn('HERE2'); });
>> warn 'created 2';
>> }
>>
>> sub run3 {
>> my $w = shift;
>> $w = AnyEvent->timer(after => 3, cb => sub { warn('HERE3'); });
>> warn 'created 3';
>> }
>>
>> View Online
>>
>> Madison Area Perl Mongers - MadMongers
>> http://www.madmongers.org
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
> --
> .Jonathan J. Miner----------------------------------------------------.
> | jon@jjminer.org | photos - http://photos.jjminer.org/ |
> | | R.A.W. #1629 - http://www.reggaeambassadors.org |
> | | LOCS Webmaster - http://www.locs-buffett.org |
> | jabber/gchat: camrycurbhopper@gmail.com AIM: camrycurbhopper |
> `---------------------------------------------------------------------'
>
> "We don't have a town drunk... We all take turns!"
> -- James Slater, "Key West Address"
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
Re: Why doesn't this script work
User:
esayward
Date: 7/15/2011 6:13 pm
Date: 7/15/2011 6:13 pm
Views: 0
Rating: 0
Rating: 0
hey, we're all in this together, somedoy I'll post
a question.. then again after how many years of being told RDFM in every irc
channel since '98... I'm almost afraid to ask a question.. ;)
----- Original Message -----From: mcholste@gmail.comTo: admin@wisbin.comSent: Friday, July 15, 2011 5:57 PMSubject: [MadTalk] Re: Why doesn't this script workmcholste wrote:
I like to serve up some softballs to make you all feel good going into
the weekend!
On Fri, Jul 15, 2011 at 5:29 PM, wrote:
> esayward wrote:
>
> so funny.. I was about to reply and there was already 4 returns...
>
> ----- Original Message -----
> From: jon@jjminer.org
> To: admin@wisbin.com
> Sent: Friday, July 15, 2011 4:26 PM
> Subject: [MadTalk] Re: Why doesn't this script work
>
> miner wrote:
>
> This is true. Returning the object is much more elegant.
>
> jon
>
> On 7/15/11 4:16 PM, rob@hoelz.ro wrote:
>
> hoelzro wrote:
>
> You're assigning your watcher objects to a local variable in run2/run3,
> so they get destroyed when those functions return. Try this:
>
> my $w2 = run2();
>
> or this:
>
> sub run2 {
> my ( $wref ) = @_;
>
> $$wref = AnyEvent->timer(...);
> }
> run2(\$w2);
>
> wrote:
>
>> mcholste wrote:
>> #!/usr/bin/perl
>> use strict;
>> use Data::Dumper;
>> use AnyEvent;
>> use EV;
>>
>> # This works as expected
>> my $w1; $w1 = AnyEvent->timer(after => 1, cb => sub
>> { warn('HERE1'); });
>>
>> my ($w2, $w3);
>>
>> # Neither of these wait for EV::loop, program exists after 1 second
>> instead of running the 2 and 3 second watchers. Why does the
>> subroutine matter?
>> run2($w2);
>> run3($w3);
>> EV::loop;
>>
>> sub run2 {
>> my $w = shift;
>> $w = AnyEvent->timer(after => 2, cb => sub { warn('HERE2'); });
>> warn 'created 2';
>> }
>>
>> sub run3 {
>> my $w = shift;
>> $w = AnyEvent->timer(after => 3, cb => sub { warn('HERE3'); });
>> warn 'created 3';
>> }
>>
>> View Online
>>
>> Madison Area Perl Mongers - MadMongers
>> http://www.madmongers.org
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
> --
> .Jonathan J. Miner----------------------------------------------------.
> | jon@jjminer.org | photos - http://photos.jjminer.org/ |
> | | R.A.W. #1629 - http://www.reggaeambassadors.org |
> | | LOCS Webmaster - http://www.locs-buffett.org |
> | jabber/gchat: camrycurbhopper@gmail.com AIM: camrycurbhopper |
> `---------------------------------------------------------------------'
>
> "We don't have a town drunk... We all take turns!"
> -- James Slater, "Key West Address"
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
Madison Area Perl Mongers - MadMongers
http://www.madmongers.org