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: Regular Expressions:
matching row with coulmn

 



genetist
Novice

Mar 18, 2013, 10:14 PM

Post #1 of 2 (10913 views)
matching row with coulmn Can't Post


Code
Hi all,  

my table looks like this,

I.D allele

1 AA

2 AA

3 AA

4 AA

5 AA

6 AA

7 AT

8 AA

i want to found different allele (AT) from allele column and store it in 3rd column

i am expecting like this

I.D ALLELE RESULT

1 AA MATCH

2 AA MATCH

3 AA MATCH

4 AA MATCH

5 AA MATCH

6 AA MATCH

7 AT NOT MATCH

8 AA MACTH

how can i do this? is regular expressions and loops will work for me to solve my problem?, please suggest me in this,

Thanks in advance

Regards,

GENTIST


hdb
New User

Mar 19, 2013, 3:06 AM

Post #2 of 2 (10908 views)
Re: [genetist] matching row with coulmn [In reply to] Can't Post

 

Code
use strict;  

my %a;
my @data = <DATA>; # read __DATA__ section
foreach (@data) {
chop;
my ($id, $allele) = split;
$a{$allele}++; # count occurences of alleles
}

my $max = 0;
$a{$_} > $a{$max} and $max = $_ for keys %a;
print "Most frequent allele: $max\n";

foreach (@data) {
chop;
my ($id, $allele) = split;
print;
print $allele =~ /$max/ ? "\tMATCH\n" : "\tNOT MATCH\n";
}



__DATA__
1 AA
2 AA
3 AA
4 AA
5 AA
6 AA
7 AT
8 AA


 
 


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

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