and the output it generates:#!/usr/local/perl510/bin/perl use strict; use warnings; use Data::Dumper; use IPC::Open3; my @plist = ( '/usr/bin/cat /etc/motd' ); 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; } print 'Before: ', Dumper \@plist; foreach ( @plist ) { print Dumper ccmexec_nodie $_; } print 'After: ', Dumper \@plist;
Now, this does NOT duplicate your problem! But, maybe you are running into something similar? Or assigning values to aliases like @_ and the values it contains (the $_[$index] variables). Or modifying @plist from within a for/foreach loop? I get the sense you are tripping over something along those lines.Before: $VAR1 = [ '/usr/bin/cat /etc/motd' ]; $VAR1 = 'Sun Microsystems Inc. SunOS 5.10 Generic January 2005 '; After: $VAR1 = [ undef ];
In that light, I would suggest you eliminate all use of default variables like $_, make sure you are always using a copy of a variable, etc. and see if that changes anything. Something like:
Good luck!!#!/usr/local/perl510/bin/perl use strict; use warnings; use Data::Dumper; use IPC::Open3; my @plist = ( '/usr/bin/cat /etc/motd' ); sub ccmexec_nodie { my( $command )= @_; my ($mystdin,$mystdout,$mystderr); my $pid = open3($mystdin,$mystdout,$mystderr,$command); my $myresult = ""; while(my $in=<$mystdout>){ $myresult .= $in; } return $myresult; } print 'Before: ', Dumper \@plist; foreach my $cmd ( @plist ) { print Dumper ccmexec_nodie $cmd; } print 'After: ', Dumper \@plist;
Elda Taluta; Sarks Sark; Ark Arks
My deviantART gallery
In reply to Re: Why are elements of my array getting deleted?
by Argel
in thread Why are elements of my array getting deleted?
by iKnowNothing
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |