Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: File handles in regular expressions

by 2teez (Priest)
on Oct 18, 2012 at 23:55 UTC ( #999831=note: print w/ replies, xml ) Need Help??


in reply to Re^2: File handles in regular expressions
in thread File handles in regular expressions

Hi Lotus1,
If so there is a problem with concatenating all the output into a scalar. $matched_lines could end up holding the whole huge file. One possible solution is to replace $matched_lines .= $match.$/; with print $fh $match.$/; Just print incrementally.

Not so, am afraid your suggestion will further affect the performance of the script, because the print function would be call as many times as the strings matches, meanwhile with the scalar used no call is placed.
Using a Profiler (NYTProf) made that very clear.
Try it.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re^3: File handles in regular expressions
Download Code
Re^4: File handles in regular expressions
by Lotus1 (Chaplain) on Oct 19, 2012 at 02:16 UTC

    If you run out of memory the performance won't be so good. I was questioning the logic of using a tied file while holding all the output in memory. The OP didn't state the file sizes or performance requirements. But since you seem to be focused on performance wouldn't it perform better to read the file into an array? For larger files the tied file will only keep part of the file in memory so it will end up rereading the file many times.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2014-12-20 05:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls