Appreciate your help#!/opt/perl-5.8.8/bin/perl -w # # use strict; use Getopt::Long; use threads; use threads::shared; use Thread::Queue; require Data::Dumper; ######## Do not modify if you do not know what you are doing!!! can de +grade performance!! ######## my $max_thread_count = 10; ###################################################################### +############################ my $version = "0.1"; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time +); sub timestamp { my $time; $time = sprintf("%04d-%02d-%02d %02d:%02d:%02d",1900 + $year, $mon ++1, $mday, $hour, $min, $sec); return($time); } my $date = $mday . $mon+1 . 1900+$year; my $promoName; my $storeList; my $workFile; my $logFile; my $ocr; my $userid; my $store; my @stores; my $thread; my $thread_list; my $tid; GetOptions( "promoname=s" => \$promoName, # promo name fo +r logging purposes "sl=s" => \$storeList, # Store List "wf=s" => \$workFile, # Work file "ocr=s" => \$ocr, # ocr "userid=s" => \$userid, # userid ); if (!$promoName || !$storeList || !$workFile || !$userid) { printUsage(); exit 1 } $logFile = "$promoName.$date.$userid.log"; sub writeLog { open(LOGFILE, ">>$logFile"); print LOGFILE ×tamp() . " $_[0]\n"; close(LOGFILE); } # usage instructions sub printUsage { print "USAGE: $0 --promoname=promo name (for logging) - REQUIRED --sl=storelist files (can be seperated by commas) - REQUIRED --wf=work file - REQUIRED --ocr=ocr #### --userid=userid - REQUIRED \n"; } # read store list(s) my $buffer; my $num_lines; sub readSL { my @list = split(/,/, $storeList); foreach my $storefile (@list) { print "opening $storefile\n"; open(STORELIST, "<$storefile"); @stores = <STORELIST>; chomp @stores; @stores = sort @stores; } } writeLog("Starting for $promoName initiated by $userid"); readSL(); my $jobs = Thread::Queue->new(@stores); # read work file sub processWF { my $val = shift; open(WORKFILE, "<$workFile"); my @lines = <WORKFILE>; #@lines = sort @lines; #chop @lines; while (defined (my $item = $jobs->dequeue)) { foreach my $line (@lines) { $line =~ s/storeplaceholder/$item/; print "running: $line"; system($line); } } close(WORKFILE); } $jobs->enqueue(undef) for 1..$max_thread_count; my @workers = map { threads->create( \processWF ) } 1..$max_thread_cou +nt; 0;
In reply to Re^10: Help needed with regard to arrays
by theknightsofni
in thread Help needed with regard to arrays
by theknightsofni
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |