The following code:

#!/usr/bin/perl -w use strict; use Tk; # use Tk qw( exit ); # Also produces same error. exit main( @ARGV ); sub main { # This part doesn't matter }
produces:
Argument "main" isn't numeric in subroutine entry at tk.pl line 6.
It appears that somehow Tk is overriding the exit() built-in in a way that doesn't define exit() as a function so that Perl interprets exit main( @ARGV ) as an "indirect object" thingy of the form "bareword bareword( args )", that is, "method package( args )", and calls "main"->exit( @ARGV ), that is, main::exit( "main", @ARGV ).

Note that you can fix the problem by changing the one line to:

exit( main( @ARGV ) );
(or by commenting out the use Tk line).

All I've found in Tk's Perl source code that appears relevant is:

use base qw(Exporter DynaLoader); @EXPORT = qw(Exists Ev exit MainLoop DoOneEvent tkinit);
There is no exit() function defined anywhere that I can find. Tk uses AutoLoading but it doesn't appear that exit() is autoloaded. So exit() must be an XS subroutine?

Any more clues as to what is going on here? Is there something that Tk could do differently to prevent this (minor) problem [other than rename Tk::exit() and provide a new Tk::exit() that is a Perl wrapper for the renamed XS function]? Or is there a change to the XS subsystem that would "fix" this?

        - tye (but my friends call me "Tye")

In reply to Tk: exit main(@ARGV); fails by tye

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.