Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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

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

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

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://606823]
[usemodperl]: this is crazy, the web is broken!
[usemodperl]: just because of banking apps on free wifi, and porn, i guess...
usemodperl thinks every1 should serve HTTP on port 80 incase we don't care about encryption, right? wtf

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2018-06-24 09:25 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.