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!

In reply to thread Scalars leaked: 1 by tart

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.