Given the following code
on win-xp (This is perl 5, version 20, subversion 1 (v5.20.1) built for MSWin32-x86-multi-thread-64int) the folowing two commands work just fineuse strict; use warnings; use Tkx; my $esub =0; use Getopt::Long; my %optdef=("esub=i" => \$esub); GetOptions (%optdef) or die("Error in command line arguments\n"); print "encapulated sub=$esub\n"; my $mw=Tkx::widget->new("."); my $connct=0; my $tkxfsr={}; $tkxfsr->{server}{port}=123; my $buf='hi'; my $remote='1234'; $connct++; my $id=time.'_'.$tkxfsr->{server}{port}.'_c'.$connct; my $afterid='serverq-'.$id; print 'SCMD '.$id.' '.$buf."\n"; $tkxfsr->{after}{$afterid}{q}=[]; for my $i (1..10){ push @{$tkxfsr->{after}{$afterid}{q}},$id.' '.$bu +f.' '.$i.('-'x10);} $tkxfsr->{after}{$afterid}{sub}=sub{ return unless ($tkxfsr->{after} && $tkxfsr->{after} +{$afterid} && $tkxfsr->{after}{$afterid}{q}); if (scalar(@{$tkxfsr->{after}{$afterid}{q}})) { accept_out_cclose_after($tkxfsr,$afterid,int(ra +nd(2000))); my $msg=shift @{$tkxfsr->{after}{$afterid}{q}}; + print 'LIST '.$msg."\n"; } else { print 'DONE '.$id.' 0'."\n"; delete $tkxfsr->{after}{$afterid}; } }; accept_out_cclose_after($tkxfsr,$afterid,500); my $d_id=Tkx::after( 20000 , sub{$mw->g_destroy}); sub accept_out_cclose_after { my $tkxfsr=shift; my $afterid=shift; my $delay=shift; my $send_id; if ($esub) { $send_id=Tkx::after( $delay , sub{&{$tkxfsr->{after}{$a +fterid}{sub}}});} else { $send_id=Tkx::after( $delay , $tkxfsr->{after}{$a +fterid}{sub} ); } $tkxfsr->{after}{$afterid}{eventid}=$send_id; $tkxfsr->{after}{$afterid}{delay}=$delay; } Tkx::MainLoop; if ( $tkxfsr->{after}{$afterid}{sub}) { print 'sub:'.$tkxfsr->{after}{$afterid}{sub}."\n"; }
but on ubuntu -14.04 (This is perl 5, version 18, subversion 2 (v5.18.2) built for i686-linux-gnu-thread-multi-64int) while -esub 1 works just fine, running -esub 0 results in an error (in tk box)perl huh-after.pl -esub 0 perl huh-after.pl -esub 1
And the ending debug statement shows the address listed is that of the perl code and it still exists after the failure window. Sometimes it fails after line 1, sometimes after line 5, or somewhere in between.invalid command name "::perl::CODE(0x96f045c)" invalid command name "::perl::CODE(0x96f045c)" while executing "::perl::CODE(0x96f045c)" ("after" script)
Anyone have any idea why the difference between the platforms, or what may be going on. My workaround is to just run the encapsulation but it seems odd to me to HAVE to do that. It took a lot of debugging and testing before i figured out to try the encapsulated method even.
Edit:add
The same thing happens under ubuntu 18.04 (This is perl 5, version 26, subversion 1 (v5.26.1) built for i686-linux-gnu-thread-multi-64int) as under ubuntu 14-04
In reply to Tkx after coderef problem by huck
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |