Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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. } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Misunderstood array behavior
by wfsp (Abbot) on Sep 20, 2008 at 07:05 UTC | |
|
Re: Misunderstood array behavior
by GrandFather (Saint) on Sep 20, 2008 at 07:12 UTC | |
|
Re: Misunderstood array behavior
by AnomalousMonk (Archbishop) on Sep 20, 2008 at 07:29 UTC | |
|
Re: Misunderstood array behavior
by jethro (Monsignor) on Sep 20, 2008 at 11:40 UTC | |
by toolic (Bishop) on Sep 20, 2008 at 15:44 UTC | |
by jethro (Monsignor) on Sep 20, 2008 at 15:57 UTC | |
|
Re: Misunderstood array behavior
by Anonymous Monk on Sep 20, 2008 at 14:53 UTC | |
by jethro (Monsignor) on Sep 20, 2008 at 16:18 UTC | |
by Anonymous Monk on Sep 20, 2008 at 17:25 UTC | |
by AZed (Monk) on Sep 20, 2008 at 19:05 UTC | |
by tinita (Parson) on Sep 21, 2008 at 10:44 UTC | |
by Anonymous Monk on Sep 22, 2008 at 02:14 UTC | |
by JadeNB (Chaplain) on Sep 22, 2008 at 19:04 UTC |