CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
how to compare rows in csv file with perl

 



genetist
Novice

Jul 24, 2013, 10:01 PM

Post #1 of 2 (670 views)
how to compare rows in csv file with perl Can't Post

Hi to all,

my data looks like this

Code pedigree A B C D E F X X1 -/- -/- -/- C/C A/A -/- Y Y1 C/C C/C A/A A/A A/A A/A

here i want to compare X1 with Y1 from coulmn A to F, if they match exactly then i would like call them as mono else poly but either of X1 or Y1 contains any of these characters -/-,z/z across all columns i would like to consider them as mono even though second row contains different characters.Please see my attached file for better understanding there i worked above procedure clearly. Now i want to compare other rows of data from A to F (I have data of 16 rows below the Y1 in my attached file) to Y1 values from A to F with the rest of values in that coulmn( upto 16 cells in pedigree column) if they match then my score will be 1 else 0, then i would like to make sum from only columns contains POLY tag. I did some basic work for this in perl and i structed some where can any one please help to solve this. This ia my code,

use strict;
use warnings;
my $file = 'perl.csv';
open my $info, $file or die "Could not open $file: $!";

while( my $line = <$info>) {
print $line;
last if $. == 19;
}
close $info;

please see my attached file for better understanding my problem and i may not explained you my problem very well,

any help would be greately appreciated

Genetist


Laurent_R
Veteran / Moderator

Jul 24, 2013, 11:23 PM

Post #2 of 2 (668 views)
Re: [genetist] how to compare rows in csv file with perl [In reply to] Can't Post

The next thing you need to do is to split your $line into an array or into individual variables:


Code
while( my $line = <$info>) { 
my @fields = split / /, $line;
print $line;
last if $. == 19;
}


Now, the @fields array containts the individual fields, you can compare $fields[0] with $fields[7] or whatever you need.

Or this;

Code
while( my $line = <$info>) { 
my ($a, $b, $c, $d, $e, $f, ...) = split / /, $line;
print $line;
last if $. == 19;
}


Same thing, you can now compare $a with $f, or whatever you need.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives