PDA

View Full Version : if statement / / UNIX & Windows


vietboy505
03-09-2006, 07:19 PM
This a section code in PERL, and it works in UNIX but not in Windows.
Can any one tell me why?

@nameTest, $x, $y are defined.
I can print it out in Unix and windows fine.

Is it because of the for loop?

##unix
for( $i=0;$i<@nameTEST;$i++){
print $nameTEST[$i]; ##work
if($nameTEST[$i] =~ /5_xplan_$x$/){

$i++;
if($nameTEST[$i] =~ /5_yplan_$y$/){
print("WORK\n\n"); ##work
}
}

}


##windows
for( $i=0;$i<$#nameTEST;$i++){
print $nameTEST[$i]; ##work
if($nameTEST[$i] =~ /5_xplan_$x$/){

$i++;
if($nameTEST[$i] =~ /5_yplan_$y$/){
print("WORK\n\n"); ##don't work, never get here
}
}

}

##windows
for( $i=0;$i<$#nameTEST;$i++){
print $nameTEST[$i]; ##work
if($nameTEST[$i] =~ /^(5_xplan_$x)$/){

$i++;
if($nameTEST[$i] =~ /^(5_yplan_$y)$/){
print("WORK\n\n"); ##don't work, never get here
}
}

}

FishMonger
03-10-2006, 09:25 AM
What results do you get when you use the same loop control for each? Currently, your unix version is looping through each element of the array, but the Windows version is looping 1 iteration less.