Fellow monks,

I'm working on a Tk app that uses the ListBox method in Tk to return results from a search. All well and good until it goes out of scope in the subroutine that sets it up.

What I am trying to do, without success up to this point, is to create a reference to this method so that I don't have a huge subroutine that both defines the list box and takes care of it's processing.

I've tried to set up my list box with a reference as:

# snippet of a subroutine that defines the widget layout my $res; { my $results = $search_frame->Listbox( -background => "white", -relief => "sunken", -borderwidth => 2, -width => 20, -height => 12, ) ->place( -in => $search_frame, -x => 20, -y => 175); $res = \$results; }

but I keep getting the message that $ref isn't defined when I try to access it later in the program by

$res->insert('end', $list[$_]->{last});

I'm assuming, and perhaps incorrectly, that when I move out of the sub that defines the listbox, I'm losing scope. But if I have to move the $ref outside as a global, doesn't that sort of defeat the purpose of defining it as a reference to the ListBox method?

I've been banging my head for a few days on this now, so any help would be greatly appreciated!

There is no emoticon for what I'm feeling now.

In reply to Calling a TK Method by reference by Popcorn Dave

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.