http://www.perlmonks.org?node_id=1049347


in reply to Its a pretty simple question.. though embarassed to ask but i am totally new in perl

OK, following your messages on the chatterbox (I was not really on-line, I just had my browser still open on Perlmonks, but was not in front of my computer), I've just prepared a new version of the code that I supplied earlier.

I can't say if it does what you want, because I am still not even sure that I understood what you really want and because I don't have actual sample files on which to run tests, but at least, I tested that it should compile cleanly without any error or warning:

use strict; use warnings; my $file1=$ARGV[0]; my $file2=$ARGV[1]; my $file3=$ARGV[2]; open my $in1, "<", $file1 or die "unable to open $file1 $!"; open my $in2, "<", $file2 or die "unable to open $file2 $!"; open my $out, '>', $file3 or die "unable to open $file3 $!"; my $header1 = <$in1>; my $header2 = <$in2>; print $out "some header for output file \n"; # now you are all set with headers, you can focus on the data while (my $line1 = <$in1>) { my $line2 = <$in2>; last unless defined $line2; chomp ($line1, $line2); my @values1 = split $line1; my @values2 = split $line2; my @values3 = map {$values1[$_] - $values2[$_]} 0..$#values1; print $out "@values3 \n"; }

This what it should do:

So, if file1 has:

foo bar baz 43 41 67

And file2 has:

foo bar baz 41 2 60

The output would be:

Some new header to be determined 2 39 7

That is at least what I understood from your initial description of your requirement.

As I already said, this program would need additional error-handling code (if the files don't match), but I am not going to go into that so long as I don't even know if this is what you need.

  • Comment on Re: Its a pretty simple question.. though embarassed to ask but i am totally new in perl
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Its a pretty simple question.. though embarassed to ask but i am totally new in perl
by gb92 (Initiate) on Aug 14, 2013 at 04:46 UTC

    thank you so much laurent sir ! understood it quite well really thanks a lot sir :) and yes this was what i needed