Apr 28, 2014, 2:28 PM
Post #3 of 9
Re: [Tejas] Problem with if condition.
[In reply to]
1. @tag is out of scope when you try to print it (it is declared within the function and the print statement is outside it). Actually, each time you call the function, a new empty version of @tag is created; the push at the end of your function is actually copying $tagged into @tag, but the @tag array is lost immediately after when you exit the function. As Bill said, you would have had an error message telling you that if you had used use strict and use warnings. You might probably also have seen it if you had indented your code correctly.
2. All your successive if conditions are not mutually exclusive. So if the last one is true, any previous value of $tagged is lost and $tagged will take the value assigned to it in the last if condition, even if other conditions were satisfied. This may or may not be what you really want. Using elsif and else statements might make your logics clearer.
3. Many or possibly all your conditions have the /\tSpreadsheet\t/ regex in them, may be this should be factored out in nested conditionals to make the rest easier to understand.
4. I do not see any reason to declare #tagged a global variable with the our statement, a "my" lexical variable would do just as good and probably better.
5. No need to chomp $edge_case, since $line was already chomped.
6. '/Trueup/i || /True-up/i' can be rewritten '/True-?up/i', making the conditional simpler.
7. I very much doubt that the code you presented compiles. In particular, this:
will not compile because:
print OUT @tag // This is nt printing anything
- // is not something introducing comments, you would need #;
- there is no semi-colon between these three lines of code;
- I do not know any Perl operator called CLOSE in uppercase.
Please provide code that at least compiles (unless your question is why it does not compile, but that's not your question).
As for your real question, I made some assumptions or hypotheses to try to give partial answers, but, if you want more, then you'll have to supply input data: I can't give answers based on guesses about what is in the data.
(This post was edited by Laurent_R on Apr 28, 2014, 2:29 PM)