Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^3: Store and match

by prasadbabu (Prior)
on Aug 11, 2009 at 07:07 UTC ( [id://787511]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Store and match
in thread Store and match

I am not clear with your inputs because in your previous node you gave [Note] in same line and now in two lines. Any how the below code will work for your above input. It will also match note_values if more than one present in a single line.

use strict; use warnings; my $prev = 0; my $total = 0; while(my $x = <DATA>){ $prev = 1 if ($x =~ /^\[Note\]$/); my $count = 0; if (($x =~ /note_values/) && $prev){ $count = $x =~ s/(note_values)/$1/g; #if more than one note_va +lues present in a line $prev = 0; } $total = $total + $count; } print "Number of occurence: $total";

Prasad

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://787511]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-19 10:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found