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 same file with perl

 



genetist
Novice

Jul 9, 2013, 2:37 AM

Post #1 of 8 (1085 views)
how to compare rows in same 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

1



X1/Y1

C/C

C/C

A/A

A/A

Z/Z

A/A

2



X1/Y1

C/C

-/-

A/A

A/A

A/A

A/A

3



X1/Y1

-/-

C/C

A/A

A/A

A/A

A/A

4



X1/Y1

Z/Z

C/C

A/A

A/A

A/A

A/A

5



X1/Y1

C/C

C/C

A/A

A/A

A/A

A/A

6



X1/Y1

-/-

-/-

-/-

-/-

A/A

-/-

7



X1/Y1

-/-

C/C

A/A

A/A

A/A

-/-

8



X1/Y1

C/C

C/C

A/A

A/A

A/A

A/A

9



X1/Y1

C/C

-/-

A/A

A/A

A/A

A/A

10



X1/Y1

C/C

C/C

A/A

A/A

A/A

A/A

11



X1/Y1

C/C

C/C

Z/Z

A/A

A/A

A/A

12



X1/Y1

C/C

-/-

A/A

A/A

A/A

A/A

13



X1/Y1

C/C

C/C

A/A

A/A

A/A

A/A

14



X1/Y1

C/C

C/C

A/A

A/A

A/A

A/A

15



X1/Y1

C/C

C/C

Z/Z

A/A

A/A

A/A

16



X1/Y1

C/C

C/C

A/A

A/A

A/A

A/A

First I count total number of different coulmnswithin a pair of X1 and Y1across from cloumn A to B, If data is missing (-/-) or unscorable (Z) for any one of X1 or Y1 with in a pair of X1Y1 then if condition consider that column is same between X1 and Y1 else that column is different. I tried folowwing code to do that but not succeed,

#!/usr/bin/perl
open(DATA,"<perl.csv");
for($column = 1 ; $column <= 8 ; $column++)
{
for($row = 1 ; $row <= 2 ; $row++)
{
if($row1==$row2)
{
$result = "EQ";
}
else
{
$result="NQ";
}
print $result;
}
print "\n";
}
, I need help in solving this problem, any help would be appreciated

thanks in advance :)


Laurent_R
Veteran / Moderator

Jul 9, 2013, 4:57 AM

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

Please include your file as an attachment to your post. With your data being refomatted by the site, it is almost impossible to know what your data really looks like.

As for your code, I can only say at this point that $row1 $row2 are not initiazlized anywhere, so that your comparison if($row1==$row2) is doomed to fail or to do something else than what yuou expect. And of course nobody can guess what they are supposed to contain.

You should always start your script with:

Code
use strict; 
use warnings;


That would force you to declare your variables (with the "my" keyword) and tell you about these types of mistakes.


genetist
Novice

Jul 9, 2013, 9:32 PM

Post #3 of 8 (1065 views)
Re: [Laurent_R] how to compare rows in same file with perl [In reply to] Can't Post

Hi Laurent sorry for that thing here in my code

#!/usr/bin/perl
open(DATA,"<perl.csv");
for($column = 1 ; $column <= 8 ; $column++)
{
for($row = 1 ; $row <= 2 ; $row++)
{
if($row1==$row2)
{
$result = "EQ";
}
else
{
$result="NQ";
}
print $result;
}
print "\n";
}

please find my attachment file
Attachments: examplefile.xlsx (9.69 KB)


Laurent_R
Veteran / Moderator

Jul 10, 2013, 5:06 AM

Post #4 of 8 (1060 views)
Re: [genetist] how to compare rows in same file with perl [In reply to] Can't Post

Hi,

first one question: is your input file an Excel file or a CSV file?

Second, I observe that the new code you posted does not take into account the comments I made about your code.

$row1 and $row2 have been neither declared, nor initialized. You can't compare them and make a decision on the outcome of the comparison. This simply cannot work.


BillKSmith
Veteran

Jul 10, 2013, 5:47 AM

Post #5 of 8 (1058 views)
Re: [genetist] how to compare rows in same file with perl [In reply to] Can't Post

I downloaded your attachment. It is a .zip file containing several excel (not csv) files. None of the files are named perl or example. If this is the correct data, please explain how to read it. If not, download the correct file.
Good Luck,
Bill


Laurent_R
Veteran / Moderator

Jul 10, 2013, 4:17 PM

Post #6 of 8 (1050 views)
Re: [BillKSmith] how to compare rows in same file with perl [In reply to] Can't Post

Bill, I *think* that the latest Excel file format is actually a zip file containing a bunch of XML sub-files. Some change having to do with the fact that numerous European (and possibly other) states (and/or perhaps the European Union) threatened not to use Excel if the file format did not become open.


BillKSmith
Veteran

Jul 10, 2013, 8:33 PM

Post #7 of 8 (1044 views)
Re: [Laurent_R] how to compare rows in same file with perl [In reply to] Can't Post

Wow, I never would have guessed. My EXCEL 2007 opens the .zip file with a warning about the wrong extension. Perhaps I should change it.
Good Luck,
Bill


BillKSmith
Veteran

Jul 10, 2013, 9:03 PM

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

I can now open your data file with EXCEL. Unfortunately, I still cannot understand your description of your problem. Perhaps, you could do one match for us by hand using the EXCEL data we already have. (Refer to the data using EXCEL's row and colulmn addresses.)
Good Luck,
Bill

 
 


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

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