LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-12-2013, 01:06 AM   #1
genetist
LQ Newbie
 
Registered: Jul 2013
Posts: 8

Rep: Reputation: Disabled
how to find match between two rows of column in same file using PERL


Hi to all my data looks like this

Code pedigree A B C D E F A B C D E F
X X1 -/- -/- -/- C/C A/A -/- eq eq eq ne eq eq
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
First I would like to count total number of different coulmns within a pair of X1 and Y1 across from cloumn A to F, If data is missing (-/-) or unscorable (Z) from cloumns A to F for any one of X1 or Y1 with in a pair of X1Y1 then 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
print("enter file name to read:\n");
$data=<stdin>;
chop($data);
for($column = 1 ; $column <= 8 ; $column++)
{
for($row = 1 ; $row <= 2 ; $row++)
{
if($row1 eq $row2)
{
$result = "EQ";
}
else
{
$result="NQ";
}
print $result;
}
print "\n";
}
any help would be appreciated
thanks
 
Old 07-12-2013, 05:54 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Well... one way is to load the file into a series of hash tables. One indexed by record number, the others by the column value, with an array of record indexes for the value(that way you also know if two or more rows have the same value, and a list of which records they were). The purpose of the first (indexed by record number) is so that you can look at the entire record where something interesting occurs.
 
Old 07-13-2013, 09:40 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
1. use
Code:
#!/usr/bin/perl
use strict;
2. Perl counts arrays from zero

3, you don't use 'data' after loading it

4. please use code tags

5. data should be an array
 
Old 07-13-2013, 11:17 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
I would use hash tables so that I don't need to hunt through an array.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Rows to Column manipulation micyew Programming 12 07-12-2012 07:13 PM
awk - rearrange column data in csv file to match columns wolverene13 Programming 9 12-21-2011 04:55 AM
deleting rows in text file in Perl shifter Programming 4 06-28-2010 07:10 PM
Column into rows bharatbsharma Programming 1 10-25-2007 02:23 AM
Parsing rows and column data from a file using perl dav_y2k Programming 1 10-08-2006 11:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration