Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found