print
map { s{0{2,}}{0}; $_ }
<DATA>;
I know this is completely OT and that in this particular case it wouldn't make a difference, but we recommend all the time against slurping files in all at once unless really needed, so please do not spread the word against this recommendation:
s/0{2,}/0/, print while <DATA>;
is not terribly more verbose. (I also changed the curlies as delimiters in the s operator because in this case they seemed confusing to me.) | [reply] [d/l] [select] |
we recommend all the time against slurping files in all at once unless really needed
Do we? How strange. Why?
Seems to me that slurping is a perfectly valid technique in the right circumstances, for instance, parsing command output or working with small to middling data sets. People have even gone to the trouble of writing modules to support the idiom.
In this case it would appear that ultibuzz has a data set of 5000000 numbers so slurping, as it turns out, would definitely not be appropriate.
Cheers, JohnGG
| [reply] |
We recommend all the time against slurping files in all at once unless really needed
Do we? How strange. Why?
Seems to me that slurping is a perfectly valid technique in the right circumstances, for instance, parsing command output or working with small to middling data sets. People have even gone to the trouble of writing modules to support the idiom.
I know that is a valid technique "in the right circumstances", that's why I didn't write "ever", but "unless really needed". Even when working with non-huge data sets it doesn't buy much after all. Nor is it really, strictly, required to "parse command output" (whatever that means - I suppose you mean the output of qx//.) The point still being that there are so many newbies here (possibly including the OP himself) and although I was the first one to specify that "in this particular case it wouldn't make a difference" (meaning precisely that the involved data set is tiny,) I'm afraid that they may see your post and think: gee, so this experienced Perl hacker uses
print map { something } <$fh>;
to iterate over the DATA filehandle, and get into the habit of doing so with all of their filehandles, which may bite them in the neck first or later, in which case we will have to tell them what's wrong with their code in another circumstance, when it may already be a rooted habit. OTOH
print something while <$fh>;
certainly doesn't do any harm with either small or huge data sets.
To be clear, in Perl TMTOWTDI all the time, granted, but there are strongly preferred means to do particular tasks. In Perl 5 the "standard" way to read over a file for processing each line of it singularly (or in relation say to the nearest neighbouring ones, but let's not be too fussy, please!) is the while loop: it even has special syntactic sugar associated to it for this particular semantics. In Perl 6, with its lazy evaluation model, we will have for pretty much for everything, but that's a whole another story. | [reply] [d/l] [select] |