Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

compare two rows in a colum file

by lakssreedhar (Acolyte)
on Aug 23, 2012 at 06:06 UTC ( #989207=perlquestion: print w/ replies, xml ) Need Help??
lakssreedhar has asked for the wisdom of the Perl Monks concerning the following question:

i have a tab delimited column file as shown

np np n_nom 3 {RP} {RP} paNiyappeVttirunna VM_RP V_RP o o o np np n_nom -3 {/RP} {/RP} np np n_nom 3 {RP} {RP} nammal VM_RP V_RP o o o np np n_nom -3 {/RP}

and there are many such sections seperated by a new line.i want to count the no.of sentences that has {RP} {RP} and {/RP} {/RP} occuring together.If the string is missing from either the 4th or 5th column then it should not be counted.

$countC = 0; while(<>) { chomp; @array = split(/\t/,$_); if($array[4] eq $array[5]) { foreach $item(@array){ if(($item =~ /{RP}/) && ($item++ =~ /{\/RP}/)) { $countC++; } } } } print"CorrectRP=>$countC\n";

Comment on compare two rows in a colum file
Select or Download Code
Replies are listed 'Best First'.
Re: compare two rows in a colum file
by moritz (Cardinal) on Aug 23, 2012 at 06:36 UTC
Re: compare two rows in a colum file
by rovf (Priest) on Aug 23, 2012 at 07:51 UTC
    i want to have the no.of sentences

    How is a sentence defined in this context?

    -- 
    Ronald Fischer <ynnor@mm.st>
Re: compare two rows in a colum file
by ww (Bishop) on Aug 23, 2012 at 12:08 UTC
    nitpick, but important: Perl is case sensitive... and your (inadequate) data sample doesn't show Rp and /RP whether occuring together or not.
Re: compare two rows in a colum file
by cheekuperl (Monk) on Aug 23, 2012 at 09:29 UTC
    no.of sentences that has both Rp and /RP occuring together
    In the same sentence i.e. line in the file??
    If so, try matching each sentence with a regex like this:
    m/RP.*\/RP/
    Question by rovf above still holds.
Re: compare two rows in a colum file
by cheekuperl (Monk) on Aug 23, 2012 at 06:14 UTC
    Please post the format properly and the code that you tried.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://989207]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2015-07-29 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls