in reply to Re^2: Avoid memory error while extracting text block
in thread Avoid memory error while extracting text block

Question: at the beginning of your code, you have a WHILE statement like so: while ( $_ = <$FH_IN`> ) !~ /START TOKEN/; I'm having difficulty interpreting this statement. So, here's my take, which I know is incorrect: while the Perl special operator has the same value as the current file handle/name, then I see the complement to the binding operator (i.e., does not bind) to my start token. I can't get there. What is the statement telling me?
  • Comment on Re^3: Avoid memory error while extracting text block

Replies are listed 'Best First'.
Re^4: Avoid memory error while extracting text block
by GotToBTru (Prior) on Apr 14, 2016 at 03:41 UTC

    Common usage has conditioned us to believe that the test condition of the while loop is what's inside the parentheses. In this case, the negative match operator is part of it as well. The body of the while loop is the 1.

    1 while ($_ = <$FH_IN) !~ /START TOKEN;

    is the equivalent of:

    while (<$FH_IN> !~ /START TOKEN/) { 1 }

    You can get Perl to show you how it interprets a statement like that using the B::Deparse module.

    $: perl -MO=Deparse -e '1 while ($_ = <>) !~ /START TOKEN/' '???' until ($_ = <ARGV>) =~ /START TOKEN/; -e syntax OK

    Perl turns the while with a negative match operator into an until with the positive operator.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)