Running Perl/Tk under Windows/XP. Tried to bind a key to a subroutine call with an argument, but it didn't work. Here is stripped-down code:

use Tk; sub print_args { $ix = 0; foreach $arg (@_) { print "ARG $ix = $arg \n"; $ix++; } print "------------------\n"; } $mw = MainWindow -> new (); $mw -> title ("Test bind with parms"); $fill = $mw -> Label (-text => "TEST BIND - try both button and dow +n arrow") -> pack (); $quit_but = $mw -> Button (-text => "QUIT", -background => "#ffffcc", -borderwidth => 5, -relief => ridge, -command => sub{exit}) -> pack (-side => bottom, -fill => "x"); $test_but = $mw -> Button (-text => "Invoke via button", -background => "#ddffff", -borderwidth => 5, -relief => ridge, -command => [ \&print_args, 3, 2, 11 ] ) -> pack (-side => bottom, -fill => "x"); $mw -> bind ('<Key-Down>' => [ \&print_args, 3, 2, 11 ]); MainLoop;
When I press the button, I get this (as expected):
ARG 0 = 3 ARG 1 = 2 ARG 2 = 11 ------------------
But when I press the down arrow:
ARG 0 = MainWindow=HASH(0x2c5c1cc) ARG 1 = 3 ARG 2 = 2 ARG 3 = 11
Oops? Known bug??

In reply to Bind mishandles arguments by Anonymous Monk

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.