http://www.perlmonks.org?node_id=1022020


in reply to require sugesstions for writing a perl script

I require suggestions for writing a perl script which reduces or uses less CPU & Memory utilization during execution of a program.

If you want suggestions for reducing the CPU or Memory of your program, you're going to have to provide a lot more details (and code) for your program. Right now, all we can do is make vague and general guesses and suggestions around the process.

As for those suggestions we can provide . . . there's a lot of ways this can potentially be improved. First of all, you need to review your validation script, and see if there are ways it can be made faster. There are lots of ways to profile your script, the most popular current tool being Devel::NYTProf. There are articles and posts out there that offer suggestions, too (such as http://stackoverflow.com/questions/4371714/how-do-i-profile-my-perl-programs).

Another thing that could help would be to move your file finding/handling into your Perl script. Running it from the shell script means that you're starting the Perl interpreter 1000 separate times. Depending on what and how many modules you're loading, that can start to add up.

I know Parallel::ForkManager has already been suggested, and you'd be wise to investigate it. It will allow you to easily process multiple files simultaneously in a more control manner. Finding the right number of concurrent processes for maximum performance may require some testing, though.

That's about all I can think of off the top of my head without more information on what validate.pl is doing, how big the files it's validating are, what format the files are, etc.

Christopher Cashell