in reply to reading file

It would be helpful if you updated your post using <code></code> tags. It is not clear what your string contains as it is. You can read about <code> tags and other helpful advice about posting on PerlMonks at Writeup Formatting Tips and Posting on PerlMonks.

Your string appears to have both newline characters and "\n" escape characters. You could clarify the content by posting the output of the command od -c filename.

You might find it helpful to break your problem down into two steps: first remove the newline characters; then search for "saravanan".

Replies are listed 'Best First'.
Re^2: reading file
by saranperl (Initiate) on Aug 04, 2009 at 08:03 UTC
    "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
      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
A reply falls below the community's threshold of quality. You may see it by logging in.