Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Faster file read, text search and replace

by hippo (Canon)
on Feb 13, 2018 at 23:06 UTC ( #1209093=note: print w/replies, xml ) Need Help??

in reply to Faster file read, text search and replace

Is there a way I can speed up the process in PERL

Without changing the approach you can speed it up by losing the unused $line scalar and the pointless chomp. Change that loop to:

while (<$bigfile>) { $lctr++; }

That should buy you a few percent. Beyond that it would be better not to process the file line by line but rather block by block with a variable (ie. tunable) block size. Maybe start with 16MB or so. Then just count the newlines in each block once it is in memory.

BTW, did you spot the bug on this line?

open my $outfile,">",$ARGV[1] or die "Error: Could not open output file $ARGV[0]:$!";

Replies are listed 'Best First'.
Re^2: Faster file read, text search and replace
by sabas (Novice) on Feb 28, 2018 at 20:08 UTC
    < yes i saw the bug $ARGV[0] should be $ARGV1 >

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1209093]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2018-06-18 13:55 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.