On Sun, 13 Mar 2005 18:38:42 +0800, Edward Wijaya <[EMAIL PROTECTED]> wrote: > Hi, > > Suppose I have a pair-series of files as follows: > > data1.fa > data1.rs > data2.fa > data2.rs #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 *.fa and *.rs > > $ perl mycode.pl data1.fa data1.rs > $ perl mycode.pl data2.fa data2.rs > > So the code is like this: > > __BEGIN__ > use warnings; > use strict; > > my $file_fa = $ARGV[0]; > my $file_rs = $ARGV[1]; > open FILE_FA, "< $file_fa" or die "Can't open $file_r : $!"; > open FILE_RS, "< $file_rs" or die "Can't open $file_p : $!"; > > my @fa_data; #these two are of the same size > my @rs_data; > > while (<FILE_FA>){ > chomp; > push @fa_data, $_; > } > > while (<FILE_RS>){ > chomp; > push @rs_data, $_; > } > > my @sum = map {$rdata[$_] + $pdata[$_]} 0..$#fa_data; > > my ($base) = split /\./,$file_fa; > print "$base\n"; > print ">\n"; > > foreach my $sum (@sum){ > > print "$sum\n"; > } > > __END__ > > 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 data1.fa and data1.rs > > data2 > sum_of_elements from data2.fa and data2.rs >
#something like this? #process each command line argument in turn while defined (my $filebase = shift;){ # the . is the string append operator $file_fa = $filebase.'.fa'; $file_rs = $filebase.'.rs'; open FILE_FA, "< $file_fa" or die "Can't open $file_r : $!"; open FILE_RS, "< $filebase" or die "Can't open $file_p : $!"; #puts each line as an element of the array my @fa_data = <FILE_FA>; my @rs_data = <FILE_RS>; #... etc }#end of while defined loop Best of luck -- Kind regards, Hal Ashburner -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>