http://qs321.pair.com?node_id=1214504

10isitch has asked for the wisdom of the Perl Monks concerning the following question:

I have a script that splits a large 15Gb file into several smaller files. It only runs on single cpu core and takes over half an hour. Can I make it run on multiple cores so it runs faster? Here's a abbreviated version. Normally it would create 13 smaller files.

use strict; print "\nSTARTING $0...\n"; if (@ARGV != 3) { print "Usage: <BNH scenario file> <Equity scenario output> <IR + scenario output>\n"; exit -1; } my $infile = $ARGV[0]; my $eqfile = $ARGV[1]; my $irfile = $ARGV[2]; my (@arr,@arr2,$w1,$w2); unless (open(INFILE, "< $infile")) {print "Error: Can not open $infile +\n"; exit -1}; unless (open(EQFILE, "> $eqfile")) {print "Error: Can not open $eqfile +!\n"; exit -1}; unless (open(IRFILE, "> $irfile")) {print "Error: Can not open $irfile +!\n"; exit -1}; while (<INFILE>) { chomp $_; if ($_ =~ /ScenSet/) { print EQFILE "$_\n"; print IRFILE "$_\n";next; +} @arr = split/\,/; if ($arr[1]) { print EQFILE ",equity,Base Scenario,0,\n"; print IRFILE ",irate,Base Scenario,0,\n"; next; } if ($arr[2]) { my @arrn = split(/\_/,$arr[2]); print EQFILE ",,eq_".$arrn[1].",1,\n"; print IRFILE ",,ir_".$arrn[1].",1,\n"; next; } if ($arr[6]) {$w1 = 0;$w2 = 0;} # riskfactor contains the string "Index" will be identified as equity +riskfactor if ($_ =~ /Index/ && $_ !~ /Credit/) { $w1 = 1;} # Assumption for IR - there will be only riskfactor USDSWAP and USDTRE +A if ($_ =~ /USDSWAP/ || $_ =~ /USDTREA/) { $w2 = 1;} if ($w1) { print EQFILE "$_\n"; } if ($w2) { print IRFILE "$_\n"; } } close INFILE; close EQFILE; close IRFILE;