I must be missing something about variable assignment or string comparison. I have a script that's going through a tab-separated file. Unless one particular value in a row is "P", I want to skip to the next line. The code looks like:
1 print "Processing inst_report file...\n";
2 foreach(@inst_report_file){
3 @line=split(/\t/);
4 ($line[13] ne "P") && next;
5 $inst_report{$line[1]}++;
6 }
For some reason, the script would never get to Line 5 even though there were clearly lines with "P" in it.
So debug time!
# Continuing to the breakpoint.
DB<13> c
main::(count.pl:27): ($line[13] ne "P") && next;
# Proving that this particular array element is indeed "P" with no leading or trailing characters.
DB<13> p "--$line[13]--\n";
--P--
# Proving that I'm not crazy and the Perl string comparison operator really works.
DB<14> p ("P" eq "P");
1
# Now since we've shown that $line[13] eq P, let's run that Boolean again.
DB<15> p ($line[13] eq "P")
# (Blank means FALSE) Whaaaat?
# Let's manually set $line[13]
DB<16> $line[13]="P"
# Now let's try that comparison again...
DB<17> p ($line[13] eq "P")
1
DB<18>
# Now it works. Why?
I can work around this by prefiltering the input file but bothers me why this doesn't work. Am I missing something obvious?
---loren---