Given the following code

use 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"; }
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 fine
perl huh-after.pl -esub 0 perl huh-after.pl -esub 1
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)
invalid command name "::perl::CODE(0x96f045c)" invalid command name "::perl::CODE(0x96f045c)" while executing "::perl::CODE(0x96f045c)" ("after" script)
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.