I have a Tk callback where I give it as arguments an anonymous hash, like so:

$canvas->bind($dk_img, "<Button-1>", [\&frst_clk, { deck => $deck, waste => $waste, img => $dk_img }]);

Well, after some experimentation, I realized the placement of how I get at the arguments is VERY important (i.e., if I don't shift the first arg off--an implicit Tk object, in this case a canvas--getting at the other one is a mess).

However, even after this, I cannot seem to get at the other argument. I'm getting unitialized errors, so I 'Data::Dumped' it, resulting in this:

$VAR1 = { 'deck' => bless( { 'next' => 0, 'num' => 0, 'max' => 52, 'cards' => [ bless( { 'state' => 'up', 'where' => $VAR1->{ +'deck'}, 'value' => 'j', 'suit' => 's' }, 'Card' ), ...more blessed cards... bless( { 'state' => 'down', 'where' => $VAR1->{ +'deck'}, 'value' => 5, 'suit' => 'c' }, 'Card' ) ] }, 'Pile' ), 'img' => 12, 'waste' => bless( { 'next' => 0, 'num' => 0, 'max' => 52 }, 'Pile' ) };

Well, I know I have what I want, so its a tricky matter of dereferencing, or what not. I figured it was an anonymous array, so I tried:

$_->{deck} ## to no avail, so then I tried: $_{deck} ## then: ${@_{deck}} ## and a bunch of other big and baggy monsters ...

How do I get at the data?

(incidentally, this is the result of a rewrite of some code I posted before about a solitaire program, viewable on my sketch pad...soon)


In reply to anonymous hashes as arguments in Tk by dimmesdale

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.