in reply to Setting flags in a conditional

Change != (numeric compare) for ne (string compare).


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Setting flags in a conditional
by mcoblentz (Scribe) on Mar 20, 2008 at 06:04 UTC
    Ooh! I thought it was simple.

    Except, it still isn't working. I also get a

    Use of uninitialized value $row in join or string at test3.pl line 80.
    error, which is the $out_fh -> print... line. Any other thoughts? Thanks for the quick look at this, much appreciated. Matt
      I thought maybe it was the location of the $in_port flag initialization - it should not be in the loop. But it's still not skipping the line nor is it setting the flag. I must have a test/condition problem. I'll look there. I'm pretty sure the code should look like this:

      my $in_port; $in_port = "false"; foreach my $ts ($te->tables) { foreach my $row ($ts->rows) { if ($row ne "Ships in port or not reporting today:") # not a ship n +ame; skip this and set the in_port flag for all remaining ships { $out_fh->print (join(',', @$row), ",", $in_port, "\n"); } else {$in_port = "true"}; } }

        Contrast if ($row ne "Ships in ... with join(',', @$row)?

        In the second example you are using $row as an array reference. In the first, as a string. To paraphrase someone, you can't just make it up and expect things to work :)

        Try printing $row and @$row inside the second loop. It may give you a clue as to what you should be looking at to detect the condition. I suspect that you should be doing something along the lines of:

        foreach my $row ($ts->rows) { if ($row->[ 3 ] ne "Ships in port or not reporting today:") { ...

        But if you print the records to the screen, print join',', @$row; then you'll be able to see which element of $row contains the text you are looking for. (Remember arrays start counting from 0.)


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.