in reply to
Re: Why are elements of my array getting deleted?
in thread Why are elements of my array getting deleted?
I was able to recreate the behavior in this script below. Note that an element of plist is getting cleared in each iteration.
use strict;
use IPC::Open3;
my @plist = ("ABC","DEF","GHI");
print "plist Before ccmexec:\n============\n",join("\n",@plist),"\n===
+=========\n\n";
my $ccmexecResult;
foreach( @plist){
$ccmexecResult = ccmexec_nodie("echo HelloWorld");
print "ccmexec returned: $ccmexecResult\n";
print "plist After ccmexec:\n============\n",join("\n",@plist),"\n
+============\n\n";
}
sub ccmexec_nodie {
my $command = $_[0];
my ($mystdin,$mystdout,$mystderr);
my $pid = open3($mystdin,$mystdout,$mystderr,$command);
my $myresult = "";
while(<$mystdout>){
$myresult = "$myresult$_";
}
return $myresult;
}
This produced the output:
plist Before ccmexec:
============
ABC
DEF
GHI
============
ccmexec returned: HelloWorld
plist After ccmexec:
============
DEF
GHI
============
ccmexec returned: HelloWorld
plist After ccmexec:
============
GHI
============
ccmexec returned: HelloWorld
plist After ccmexec:
============
============