The files had tables in them like these. Min. file
Site1 Site2
3 4
5 6
5 8
And then a similar looking .max file. I couldn't write a script to combine them to a single file that would contain field that have "min - max" in them. I made a workaround and combined those two .csv files into one. Then I was able to write and use this simple script.
#!/usr/bin/perl -w open IN, "minmaxin.csv" || die ("did not open infile"); open OUT, ">>minmaxtoprint.csv" || die ("did not open outfile"); while (<IN>) { my @line = split(/,/, $_); print OUT "$line[0]-$line[4],$line[1]-$line[5],$line[2]-$line[6],$line +[3]-$line[7]";} close IN; close OUT;
(As you can see there were four test sites.) Why I made my first post. Is this reason - It is not easy for me to write a script that combines two input files. I have learned as much that i can make simple scripts to modify one file. But regularily I came to a problem like this. A sample code - to illustrate my stupidity/greenness.
#!/usr/bin/perl -w open MIN, "min.csv" || die ("did not open infile"); open MAX "max.csv" || die ("did not open infile"); open OUT, ">>minmaxtoprint.csv" || die ("did not open outfile"); while (<MIN>) { my @minline = split(/,/, $_); while (<MAX>){my @maxline = split(/,/, $_);}, print OUT "$minline[0]$l +ine[0] ... etc
Which will obviously not work. The problem is more genral actually - how to I iterate through elements of one entity (file, array etc) while adding/substracting/interacting with elements corresponding to another? That is a thing I would very much like to learn.

To learn is the reason I joined this site, I'm right now in my "knowledge" of perl only limited to what stuff I have been able to find online. I have had no teacher whatsoever :(


In reply to Re^2: Combining two .csv files by naturalsciences
in thread Combining two .csv files by naturalsciences

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.