in reply to split loop error

What's the exact error message?
Is it a run-time or a compile-time error?


MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
** The Third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re: Re: split loop error
by tpederse (Sexton) on Feb 03, 2003 at 02:47 UTC
    it's a run time error:
    Split loop, <> line 1.
    The program looks like this...
    while (<>) { ## fails on linux i386 multi thread $line = $_; @outLine = split(/(<[^>]*>)/,$line); ## works on linux i386 multi thread ## @outLine = split(/(<[^>]*>)/,$_); }
      There we go. It's very likely that it may be a bug. You're using one of those common idioms that a lot of people (including me), simply don't like. Here's how I'd write it (see <> in `perldoc perlop'):
      while(my $line = <>){ ... }
      Unless you're exploiting the magic of <> (you're simply reading of STDIN), or you have no idea there is any magic, i'd suggest you simply read off the filehandle you're using (as in <STDIN>).

      I personally like to go all the way and use defined, as in while(defined(my $line = <>)){...}.

      From perldoc perldiag

      Split loop
      (P) The split was looping infinitely. (Obviously, a split shouldn't iterate more times than there are characters of input, which is what happened.) See split in perlfunc.

      update: Try $line = "$_"; and see if that works (it may be that somehow $line was being aliased to $_ instead of a copy being made, and that somehow screwed up the length count -- wild guess).


      MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
      ** The Third rule of perl club is a statement of fact: pod is sexy.

      I find it hard to believe there could be a bug in something so commonly used as "while (<>)" or in the assignment of a scalar from $_. If there were, all sorts of other things would be breaking.

      The only thing that is slightly unusual about this split is the use of capturing parenthesis. Does the split still break if you take them out? (I know you need them to capture the angle brackets and what's inside them, but it might help to narrow down the bug if you tried that).

        Thanks again for the feedback.

        I verified that the problem isn't really with the while (<>) type of idiom nor with the assignment of a scalar. As tall man suggests those are pretty common operations and it would be utter chaos if they broke like this. Why the error messages points to line 1 is yet another question.

        The problem is in the regex of the split statement. If I do as tall man suggests and remove the capturing parenthesis, the error continues. However, if I pare things down to ...

        @outLine = split(/(<.*>)/,$line);
        and this works as it should. Of course, this is not the same as what I want to do, but I think it helps to isolate the problem.

        So, I'm fairly near convinced there is a bug in the split regex handling of i386 multi thread. Am I missing something here?

        Thanks! Ted