in reply to Re^4: Removing and replacing values from an array.
in thread Removing and replacing values from an array.

this code will push both URLs and IPs into both arrays
I'll assume you mean the script version, as opposed to the one-liner. You're forgetting that the reads are stateful. Specifically,
while (<>){ last if !/\S/; ... }
reads STDIN until it sees an empty line, and then bails. The second while (<>){ begins at that point, so if he has an empty line delimiting his IP and URL blocks, the first loop reads only the first block, and the second loop reads only the second. There is no seek, so I can' be reading the input twice.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^6: Removing and replacing values from an array.
by Laurent_R (Canon) on Aug 18, 2014 at 18:55 UTC
    Sorry, Kenneth, I had not seen anywhere any specification that there is an empty line delimiting the IP and URL blocks. Rereading the whole thread, it is true that the data pseudo-sample provided has one such separator, but is there any guarantee that there are just one IP block and one URL block and not several blocks of each type? Or that the block will always really be in that order?

    I personally would not rely on that unless I have a firm commitment from the data supplier that it will be always this way and exactly this way (or unless I am producing myself the data, say in another application). In brief, I still think it would be safer and more robust to perform some validation of the type of data at hand (but, of course, with a better regex than the really basic one I provided).