There's more than one way to do things | |
PerlMonks |
How much can this text processing be optimized?by YAFZ (Pilgrim) |
on May 16, 2005 at 13:36 UTC ( [id://457448]=perlquestion: print w/replies, xml ) | Need Help?? |
YAFZ has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
I have written a simple Perl code to do some text processing but I'm sure it may be optimized. The tast is to process a text file, delete garbage from it and count the words inside (using hash), and then print out the list of the words alphabetically with their numbers on the second column. By garbage I mean strings which include numbers like: 345asfg435t, 345gf, er345, etc.
So here is the code (some characters in regex patt. may not display correct in your browsers because they are Turkish charachers, oops! they are converted to entities, anyway):
This code is run on Win2K ActiveState perl version v5.8 in such a fashion: perl csharpversusperl.pl<input.txt >output.txt I'm comparing it with C# programs (done for an assignment) and C# programs also use command line redirection, not some system file processing methods. The current situation is that this Perl code takes 10 seconds to process a 750K file but one of the C# code (not very optimized though) takes about 3-4 seconds. I'd like to learn if this code could be much faster, if I'm doing something wrong. Please enlighten me.
Back to
Seekers of Perl Wisdom
|
|