in reply to Object Functions and Threading
my $downloader = eval { new Downloader() } or die($@); my $thread1 = threads->new( sub { $downloader->fetch("http://www.webaddress.com", \%siteHash); } ); $thread1->join;
The (anonymous) sub will close over $downloader and %siteHash (assuming they are both lexical (my) variables), so they will be accessible to the sub even if they go out of scope.
By the way, I changed die(@_) to die($@). Check perlvar if you're not sure which to use.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Object Functions and Threading
by ramblinpeck (Sexton) on Jan 30, 2006 at 19:26 UTC | |
by BrowserUk (Patriarch) on Jan 30, 2006 at 20:24 UTC |