Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Stuck in komplexer regex, at least for me

by blazar (Canon)
on Mar 27, 2007 at 09:22 UTC ( #606721=note: print w/ replies, xml ) Need Help??


in reply to Re: Stuck in komplexer regex, at least for me
in thread Stuck in komplexer regex, at least for me

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.)


Comment on Re^2: Stuck in komplexer regex, at least for me
Select or Download Code
Re^3: Stuck in komplexer regex, at least for me
by johngg (Abbot) on Mar 27, 2007 at 13:17 UTC
    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

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://606721]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (12)
As of 2014-09-22 11:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (189 votes), past polls