sabas has asked for the wisdom of the Perl Monks concerning the following question:
I have a large xml file that has 946,388,628 lines. I created a simple .pl script to read and count the lines but it took so long just to finish reading the whole file without any logic added just read each line and count it. Is there a way I can speed up the process in PERL (I am new in PERL). I am planning to search for a certain "old string" in each line and replace with the "new string".
$ARGV[0] or die "ERROR: No file for 114 lines"; $ARGV[1] or die "ERROR: No file for 114 lines"; open my $bigfile,"<",$ARGV[0] or die "ERROR: COuld not open big file $ +ARGV[0]:$!"; open my $outfile,">",$ARGV[1] or die "Error: Could not open output fil +e $ARGV[0]:$!"; $datestring = localtime(); print $outfile "Processing started...at $datestring\n"; print "Processing started...at $datestring\n"; my $lctr = 0; while (my $line = <$bigfile>) { chomp $line; $lctr++; } $datestring = localtime(); print $outfile "Processing Ended...at $datestring\n"; print $outfile "Total Lines read in $ARGV[0] = $lctr"; close $bigfile; close $outfile;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Faster file read, text search and replace
by hippo (Archbishop) on Feb 13, 2018 at 23:06 UTC | |
by sabas (Acolyte) on Feb 28, 2018 at 20:08 UTC | |
Re: Faster file read, text search and replace
by NetWallah (Canon) on Feb 14, 2018 at 04:56 UTC | |
by Jenda (Abbot) on Feb 14, 2018 at 11:58 UTC | |
Re: Faster file read, text search and replace
by Jenda (Abbot) on Feb 14, 2018 at 12:18 UTC | |
Re: Faster file read, text search and replace
by haukex (Archbishop) on Feb 13, 2018 at 22:28 UTC | |
Re: Faster file read, text search and replace
by Cristoforo (Curate) on Feb 14, 2018 at 20:29 UTC |