in reply to Re: Combining two .csv files
in thread Combining two .csv files
| Site1 | Site2 |
| 3 | 4 |
| 5 | 6 |
| 5 | 8 |
(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 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;
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.#!/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
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 :(
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Combining two .csv files
by kcott (Archbishop) on Nov 29, 2010 at 15:52 UTC | |
by naturalsciences (Beadle) on Nov 29, 2010 at 16:14 UTC | |
|
Re^3: Combining two .csv files
by tospo (Hermit) on Nov 29, 2010 at 16:18 UTC |