in reply to Reading a huge input line in parts

What is wrong with the last number? Is it ignored? Then undo your setting of $/ and read again. Does it have a newline? Then use a regex to get rid of it. In any case I would think you should chomp your input to get rid of the blanks.

Update: try to add s/\s//g before your call to do_something.

Replies are listed 'Best First'.
Re^2: Reading a huge input line in parts
by kroach (Pilgrim) on May 04, 2015 at 15:59 UTC
    The last number is not read unless eof is encountered. I can't undo the setting of $/ and read again because I have no way of detecting the last number. If I undo it midway I would get the rest of the line, which could be enormous.

      I cannot reproduce your problem but I was thinking of

      use strict; use warnings; sub do_something { print '{', $_[0], "}\n" } { local $/ = ' '; while (<>) { do_something($_); } } do_something(<>);
      It should not be to costly in terms of resources and performance to check if you have a space at the beginning and at the end of each chunk of data before splitting it, and reconstruct the boundary numbers accordingly, especially if your read data chunks are relatively large.

      Update: Ooops, this was meant as an answer to the following post: Re^2: Reading a huge input line in parts, sorry for inconvenience.

      Je suis Charlie.