It took me a long time to see the cause of this, (but it was processing 1 GB of data), and I thought it might prove interesting/amusing to others.

Greatly simplified from the original that was processing data from a file, this program never terminates. Can you see why?

#! perl -slw use strict; my @bits = unpack '(a3)*', 'abcdefghijklmnopqrstuvwxyz'; 1 while "@bits[3,5,7]" =~ m[vwx]g;

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.

Replies are listed 'Best First'.
Re: Program enters infinite loop, can you see why?
by ikegami (Patriarch) on Dec 07, 2010 at 03:58 UTC
      (Ray's lightbulb comes on.) Thanks Ikegami! This explanation makes best sense.
Re: Program enters infinite loop, can you see why?
by JavaFan (Canon) on Dec 07, 2010 at 10:09 UTC
    It's one of the cases where quoting your variables can have an unexpected effect:
    $x = "abc"; say 1 while $x =~ /c/g; say 2 while "$x" =~ /c/g;
    will print a single 1, and an unlimited number of 2s.
Re: Program enters infinite loop, can you see why?
by Anonymous Monk on Dec 07, 2010 at 03:56 UTC

      By that logic, this should also hang, but it doesn't:

      C:\test>perl -wE"1 while 'vwx' =~ m[vwx]g;"

      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.
        interpolation always interpolates
Re: Program enters infinite loop, can you see why?
by pajout (Curate) on Dec 07, 2010 at 10:14 UTC
    The condition of the cycle is NOT changed due one loop...