Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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:

  • read the first line of file1 and file 2 (the headers) and discard them;
  • write a silly header in file3 (you can just change it in accordance with your needs);
  • read into $line1 and $line2 the next line from file1 and file2 respectively;
  • split $line1 and $line2 into the @values1 and @values2 arrays;
  • substract respective values of @values2 from @values1;
  • output the restults of these substractions to the output file;
  • repeat the last four steps for the next line, until the files are exhausted.

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.


In reply to Re: Its a pretty simple question.. though embarassed to ask but i am totally new in perl by Laurent_R
in thread Its a pretty simple question.. though embarassed to ask but i am totally new in perl by gb92

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (8)
    As of 2018-11-13 18:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My code is most likely broken because:
















      Results (158 votes). Check out past polls.

      Notices?