Dear Monks,
Suppose I have a pair-series of files as follows:
data1R.fa data2P.fa data2R.fa data2P.fa #say each of this file contain lines of numbers .... #and there are 40 of files
And I have a code that take two files that ends with *R.fa and *P.fa
perl mycode.pl data1R.fa data1P.fa perl mycode.pl data2R.fa data2P.fa
So the code is like this:
use warnings; use strict; my $file_r = $ARGV[0]; my $file_r = $ARGV[1]; open FILE_R, "< $file_r" or die "Can't open $file_r : $!"; open FILE_P, "< $file_p" or die "Can't open $file_p : $!"; my @rdata; my @pdata; #these two are of the same size while (<FILE_R>){ chomp; push @rdata, $_; } while (<FILE_P>){ chomp; push @pdata, $_; } my @sum = map {$rdata[$_] + $pdata[$_]} 0..$#pdata; print "$file_r\n"; print ">\n"; foreach my $sum (@sum){ print "$sum\n"; }
How can I make my code above such that it can take all multiple files iteratively? to give output sth like this:
>data1 sum_of_elements from data1R.fa and data1P.fa >data2 sum_of_elements from data2R.fa and data2P.fa
Regards,
Edward

Update:
Correction has been made to the code above, apologize for it.

In reply to Finding Files and Processing them iteratively by monkfan

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.