Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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
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.
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 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 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.

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 surveying the Monastery: (14)
As of 2014-08-27 18:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (248 votes), past polls