M
mattbreedlove
Using Perl v5.8.4
This type of problem has plagued me over the years several times. Each
time I have had to rearrange the way that my PERL script was designed
to work around it.
At this point I think its a bug or something really strange.
I was able to reproduce it with the test script below.
The issue is that a global list variable that is built inside
subroutine A, iterated over in a foreach loop in subroutine B, is then
magically undefined after the foreach loop if the loop contains a
command pipe with a while loop.
According the laws of PERL that I am used to when you run the below
script you *should* get:
main_before-ITERATE_HOSTS -apple orange durian-
start_inside_ITERATE_HOSTS -apple orange durian-
end_inside_ITERATE_HOSTS -apple orange durian-
main_after-ITERATE_HOSTS -apple orange durian-
However instead you get
main_before-ITERATE_HOSTS -apple orange durian-
start_inside_ITERATE_HOSTS -apple orange durian-
end_inside_ITERATE_HOSTS - -
main_after-ITERATE_HOSTS - -
Any ideas?
Here is the test script:
#!perl
SETUP_HOSTS();
print "main_before-ITERATE_HOSTS -@SLAVE_HOSTS-\n";
ITERATE_HOSTS();
print "main_after-ITERATE_HOSTS -@SLAVE_HOSTS-\n";
sub SETUP_HOSTS {
push(@SLAVE_HOSTS, apple);
push(@SLAVE_HOSTS, orange);
push(@SLAVE_HOSTS, durian);
}
sub ITERATE_HOSTS {
print "start_inside_ITERATE_HOSTS -@SLAVE_HOSTS-\n";
foreach (@SLAVE_HOSTS) {
$REMOTE_HOST="$_";
#open(CMD, "$SSH $REMOTE_HOST 'do some stuff'|");
while(<CMD>) {
chomp;
$LINE="$_";
if ( "$LINE" =~ /service id\=/ ) {
print "blah\n";
}
}
close(CMD);
}
print "end_inside_ITERATE_HOSTS -@SLAVE_HOSTS-\n";
}
This type of problem has plagued me over the years several times. Each
time I have had to rearrange the way that my PERL script was designed
to work around it.
At this point I think its a bug or something really strange.
I was able to reproduce it with the test script below.
The issue is that a global list variable that is built inside
subroutine A, iterated over in a foreach loop in subroutine B, is then
magically undefined after the foreach loop if the loop contains a
command pipe with a while loop.
According the laws of PERL that I am used to when you run the below
script you *should* get:
main_before-ITERATE_HOSTS -apple orange durian-
start_inside_ITERATE_HOSTS -apple orange durian-
end_inside_ITERATE_HOSTS -apple orange durian-
main_after-ITERATE_HOSTS -apple orange durian-
However instead you get
main_before-ITERATE_HOSTS -apple orange durian-
start_inside_ITERATE_HOSTS -apple orange durian-
end_inside_ITERATE_HOSTS - -
main_after-ITERATE_HOSTS - -
Any ideas?
Here is the test script:
#!perl
SETUP_HOSTS();
print "main_before-ITERATE_HOSTS -@SLAVE_HOSTS-\n";
ITERATE_HOSTS();
print "main_after-ITERATE_HOSTS -@SLAVE_HOSTS-\n";
sub SETUP_HOSTS {
push(@SLAVE_HOSTS, apple);
push(@SLAVE_HOSTS, orange);
push(@SLAVE_HOSTS, durian);
}
sub ITERATE_HOSTS {
print "start_inside_ITERATE_HOSTS -@SLAVE_HOSTS-\n";
foreach (@SLAVE_HOSTS) {
$REMOTE_HOST="$_";
#open(CMD, "$SSH $REMOTE_HOST 'do some stuff'|");
while(<CMD>) {
chomp;
$LINE="$_";
if ( "$LINE" =~ /service id\=/ ) {
print "blah\n";
}
}
close(CMD);
}
print "end_inside_ITERATE_HOSTS -@SLAVE_HOSTS-\n";
}