in reply to Re: reading file
in thread reading file

"a student name is sa\n ravanan. saravanan is studying 3rd standard. i am go with sara\n vanan"
this above string is in file. I want to match "saravanan". matching count should be 3 thanks

Replies are listed 'Best First'.
Re^3: reading file
by biohisham (Priest) on Aug 04, 2009 at 11:55 UTC
    I could think of this very simple code, it gives you an idea about creating a list, that list is saved in @array and then for each element in the array there happens a match check that increments the count when true, you have each element checked and the checking goes on till all the array elements have been checked for the pattern /\bsaravanan\b/ ...
    !/usr/local/bin/perl $string="a student name is sa\nravanan. saravanan is studying 3rd stan +dard.i am go with sara\nvanan"; $count = 0; $string =~s/\n//g; #removing \n print "$string\n"; @array = split(" ", $string); #making the string into individual +list elements foreach $element(@array){ if($element=~/\bsaravanan\b/){ $count++; } } print "found: $count matches.\n";
    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind