|XP is just a number|
Reading a huge input line in partsby kroach (Pilgrim)
|on May 04, 2015 at 13:20 UTC||Need Help??|
kroach has asked for the wisdom of the Perl Monks concerning the following question:
I need to read a line of numbers separated by spaces and ending with a 0, like this:1 2 3 4 7 20 12334 0
Each number needs to only be processed individually, so I don't have to keep them all in memory. The problem is, input lines can be very long and reading them with <> and splitting consumes a lot of memory.
I tried setting a space as the input record separator, but it doesn't get the last number correctly.
I also tried to simulate C++ cin behaviour with the following function:
However, it's overly complicated and slow.
How else could I go about doing this?EDIT: Updated sample input to include multi-digit numbers