tart has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I was trying to implement the thread reading one of the perl wishdom blog,

I tried following, which works successfully without any error,
use strict; use warnings; use threads; use threads::shared; main(); sub main { my @arr = ( 'ssh user@host rm -rf /cygdrive/mobile', 'ssh user@host mkdir /cygdrive/mobile', ); foreach my $key(@arr) { my $path = '/home/tart/tmp/'; execute($path, $key); } } sub execute { my $path = shift; my $cmd = shift; chdir($path) || die"Cant change patch $path\n"; my $done :shared = 0; my @out; async { @out = `$cmd &`; if($?) { print "Error: $cmd\n"; } $done = 1; }->detach; until($done) { for(1 .. 20 ) { sleep 1; last if $done; } verbose($cmd); } print "@out\n"; } sub verbose { my $cmd = shift; print "Still executing: $cmd\n"; }
But when I try to do same thing with one of my existing script,

where, Commands are loaded into hash from .cfg (configuration file) and passed to subroutine where execution happens exactly like above. And error are passed into different subroutines,

Example: -
sub execute { my $infoHR = shift; my $setupHR = shift; my $path; my $command; $path = $infoHR->{PATH}{$setupHR->{list}->{pth}}; $command = $infoHR->{COMMAND}{$setupHR->{list}->{cmd}}; $path =~ s/^\s+//; $path =~ s/\s+$//; $command =~ s/^\s+//; $command =~ s/\s+$//; changeDirectory($path) || die "Unable to change dir to $path\n"; my $done:shared = 0; my $failed:shared = 0; my @systemOut:shared; async { @systemOut = `$command 2>&1`; if($?) { $failed = 1; } $done = 1; }->detach; until($done) { for(1 .. 20 ) { sleep 1; last if $done; } verbose(Running, $command); } unless($failed) { verbose(Success, $command); return 1; } return errFound($setupHR, Error $command); }
But when I execute that script I am getting,
Scalars leaked: 1
I am so surprised I checked both script more than 10 time I guess,
Looking for help!!!
Cheers, Updates: Removed duplicate lines (due to copy paste from script) Thanks to BrowserUk!

Replies are listed 'Best First'.
Re: thread Scalars leaked: 1
by VinsWorldcom (Prior) on Sep 01, 2010 at 12:20 UTC
Re: thread Scalars leaked: 1
by BrowserUk (Patriarch) on Sep 01, 2010 at 12:34 UTC
    I am so surprised I checked both script more than 10 time I guess,

    Really? How come you didn't notice this?

    async { async {

    If you post (copy & paste) the complete program that gives the error, rather than forcing people to try and reconstruct your problem, by mixing and matching bits of this and that, whilst fixing typos, you're more likely to get a response.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.