Thanks again to zentara for helping me out with my threading issue in wxPerl. One last obtsacle I'm facing is how do I pass a blessed object into a new thread? I have an example wxPerl app seen here. My last issue is passing the constructor object from Net::Twitter into a new thread. I've taken zentara's advice and created my worker threads prior to my UI creation and this works great. (My script no longer crashes on OS X 10.5 :) ) Currently my script creates a $twit object by logging into Twitter, but passing that blessed object to my worker thread is proving to be a challenge and I'm not sure what the best method is.

As you'll see I already have a shared hash called:

use threads; use threads::shared; use Thread::Queue; use Wx; my %thread_hash; share(%thread_hash); # ... # create $twit object eval { my $twit = Net::Twitter->new( { username => $username, password => $password, } ); if ( defined $twit ) { # I've tried setting it here # but it complains ... $thread_hash{'twit'} = $twit; # This works fine, and it's what I currently call # but I can't access this from the thread because # the worker thread was created way before any # of this code. $self->{twit} = $twit; } }; if ( my $err = $@ ) { return; } # ... # starting my actual thread sub StartThread { my ($self, $event) = @_; use Data::Dumper; print Dumper( %thread_hash ); $self->{queue}->enqueue('GO'); }
But trying to pass the blessed $twit object into the shared data structure doesn't work.

Any advice or examples would be grealy appreciated.
Thanks


In reply to passing shared blessed object? 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.