Am I going crazy with the Perl string comparison operator? Debug log included -
I should remember something about variable assignment or string comparison. I have a script that is running through a different file from one tab. Unless there is a special value in the line "P", I go to the next line, the code looks like this:
1 print "processing inst_report file ... \ n"; 2 foreign (@inst_report_file) {3 @ line = partition (/ \ t /); 4 ($ line [13] "p") & amp; Amp; the upcoming; 5 $ inst_report {$ line [1]} ++; 6} For some reason, the script will never be found on line 5, even if there are clearly lines with "P" in it.
Then debug time!
# continue the breakpoint of the DB & lt; 13 & gt; C Main :: (count.pl:27): ($ line [13] "P") & amp; Amp; the upcoming; Explaining that this particular array element is actually "P", in which there is no leading or trailing character. DB & lt; 13 & gt; P "- $ line [13] - \ n"; - P - # Prove that I am not mad and the Perl string comparison operator actually works. DB & lt; 14 & gt; P ("p" ek "p"); 1 # Now we have shown that the line $ [13] ek p, let's go boolean again. DB & lt; 15 & gt; P ($ line [13] eq "p") # (empty means wrong) watt? # Come and set $ line manually [13] DB < 16 & gt; $ Line [13] = "P" # Now we try that comparison ... db < 17 & gt; P ($ line [13] eq "p") 1 db < 18 & gt; # Now it is working. Why? I can work by prefining the input file around it, but bothers me why it does not work. Am I clarifying something?
--- Lorraine ---
Find out that your string is actually What is using:
Use the data: Dumper; Local $ Data :: Dumper :: Use CQ = 1; Print (dumper ($ line [13]));
[On the further review, the estimations given below are most incorrect.]
I suspect that you have a trailing new line, the situation where You want in
You may have an empty space behind. Both s / \ s + \ z // will remove the following spaces and subsequent Newline.
Comments
Post a Comment