more useful options | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I had taken a chance of reading the weblink that you wrote but after 30 seconds I gave up... so I will try to give only general advices here. First of all, don't do this: $ ./test < textfile | sort | uniqPerl has more then enough tools to do the job that is done with sort and uniq programs. System calls are expensive and sometimes the speed of those programs doesn't pay for the cost of invoking them. To read the file, use open function. If the file is not that big, you can read it entirely and put into memory like this:
This will speed up things than using while block. Use an array to keep the results from the string:
You can even avoid using if statement to do that. For the next string to process, do a @results = () to start again with zeros. Try as much as you can to avoid using next loops with for. Look for the Schwartzian Transform to see how to improve your code. Try using @sequence = split( //, $sequence ) instead of a other loop. And last but not least, check the Benchmark module to test all those things.
Alceu Rodrigues de Freitas Junior --------------------------------- "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill In reply to Re: Longest repeated string...
by glasswalk3r
|
|