everthing prints just fine. Also if I use a foreach loop on the arrays individually, everything prints fine. But if I use a nested loop (because I want to search for a value in the second loop), the last item in the array is "missing." Strangely, if I print the value using the debugger, the value is there...hope that makes sense. Here's my code:print "@firstLine1\n"; print "@firstLine2\n";
Any help is appreciated. Thanks in advance.open my $fileText, '<', $file or die("Error opening \"$ARGV[0]\": $! " +); my @firstLine1; my $count = 0; while(<$fileText>){ chomp; if($count++ == 0){ # I will eventually read the whole file... @firstLine1 = split(/\t/); last; } } open my $fileText2, '<', $ARGV[1] or die("Error opening \"$ARGV[1]\": +$! "); my @firstLine2; $count = 0; while(<$fileText2>){ chomp; if($count++ == 0){ # I will eventually read the whole file... @firstLine2 = split(/\t/); last; } } print "@firstLine1\n"; # All values print fine! print "@firstLine2\n"; # All values print fine! foreach my $sample1 (@firstLine1){ foreach my $sample2 (@firstLine2){ # I get some strange output here. # Everything will print fine -> # $sample1: <sample1_value> $sample2: <sample2_value> # until the last value in the array, # everything gets messed up -> # sample1:$sample2: <sample2_value> print "\$sample1: \"$sample1\"\t\$sample2: \"$sample2\"\n"; } # If I try a compare, it fails if($sample1 eq $sample2){ # doesn't get here on the last value. } }
In reply to Misunderstood array behavior by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |