Hi all,
I am working on a script where u read multiple files from a folder after applying filter on the name of the file. And I write this in a single file.

Now I need to speed things up i wish to split the whole process in no of instances. I wrote the following code, but am not able to get the expected result.
use strict; use warnings; opendir DATDIR, "dats/"; my @files = grep { $_ ne '.' && $_ ne '..' } readdir (DATDIR); my $dat = "dats/"; #my @files = <$dat/*.*>; my @datfiles = sort {$a cmp $b} @files; my @print = ""; my $toNumofFiles = @datfiles; my $instance = 5; my $report = "2010_01"; my $filesperinstance; my $remainingfiles; my $print; if($toNumofFiles < $instance) { $filesperinstance =1; $instance = $toNumofFiles; } else { $filesperinstance= $toNumofFiles / $instance; $remainingfiles = $toNumofFiles % $instance; } my @childs = (); my $startArrayIndex = 0; my $endArrayIndex=$filesperinstance; for(1..$instance) { if ($remainingfiles !=0) { $endArrayIndex = $endArrayIndex + 1; $remainingfiles = $remainingfiles -1; } my $pid = fork(); if($pid) { push(@childs,$pid); } elsif($pid==0) { my $locStartArrayIndex = $startArrayIndex; my $locEndArrayIndex = $endArrayIndex; for (my $fileIndex = $locStartArrayIndex; $fileIndex < $locEnd +ArrayIndex; $fileIndex++) { if($datfiles[$fileIndex] =~ m/^$report/) { print $datfiles[$fileIndex],"\n\n"; my $datDir = "dats/$datfiles[$fileIndex]"; print $datDir,"\nDat Dir\n"; read FILE, "< $datDir"; @print = <FILE>; } } exit(0); } else { exit; } $startArrayIndex = $endArrayIndex; $endArrayIndex = $endArrayIndex + $filesperinstance; print $_,"\ninstance \n"; } foreach(@childs) { waitpid($_,0); } print @print,"\nPrint\n";


I am getting this error
Can't modify string in read at try.pl line 62, near ""< $datDir";" Not enough arguments for read at try.pl line 62, near ""< $datDir";" Execution of try.pl aborted due to compilation errors.
Kindly tell me where I going wrong?

Thanks
AvantA

In reply to how do I create parrallel processing in this script? by avanta

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.