Hello Everybody,
I want to search for a pattern like this
'(a\s*bcd\s*e)(f\s*ghi)(jkl\s*tr)
in a file. (The characters and the spaces can change in the pattern to be searched). I want to find the no. of occurences of the particular pattern in the file and if the pattern occurs once then I had to extract $1,$2,$3 and the pos of that found pattern. I am able to do like this
$pattern = (reement\s*PFPC\s*receives\s*fees\s*at\s*annual\s*rate\s*of
+\s*)(#.{0,3}#)(\s*\s*of\s*average\s*net\s*asset\s*value\s*of\s*outsta
+nding\s*In\s*)
while ($data =~m/$pattern/gi)
{
$counter_number_of_search+=1;
}
if ($counter_number_of_search == 1)
{
##### Do some operation ########
}
else
{
####### increase the margin to search #####
}
How can I find out the no. of occurences of the string in the data without going into the while loop.
Please get a way out!!!!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.