Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-25 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found