Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Optimise file line by line parsing, substitute SPLIT

by nbtrap (Sexton)
on Jun 06, 2013 at 02:04 UTC ( #1037347=note: print w/ replies, xml ) Need Help??


in reply to Optimise file line by line parsing, substitute SPLIT

If memory is not lacking, you can slurp the entire file and then process the lines, as in:

#!/usr/bin/perl use warnings; use strict; my $file = "/Path/to/file/file_X.txt"; open(my $fh, '<', $file) or die("Can not open file $file to read!\n"); my @lines = <$fh>; close($fh); for (@lines) { chomp; ## process the rest here, including calls to split } print "\n# of lines: " . scalar(@lines) . "\n";
This has a good chance to speed things up, presumably because perl will make fewer calls to read(2).


Comment on Re: Optimise file line by line parsing, substitute SPLIT
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1037347]
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: (14)
As of 2014-12-26 17:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (174 votes), past polls