Mandar Rahurkar wrote:
I need to searh through a text file and lookfor a keyword and print
the immediate word following it and before it. for eg.,
$_="bird was eating fish";
output for keyword eating shd be: was eating fish
this is what i am doing,
$key="dog";
@sspace=`cat file.txt`;
foreach(@sspace) {
/ (.*) $key \w/;
Err.. How about making a *serious* attempt to get a grasp of regexes?
http://www.perldoc.com/perl5.8.4/pod/perlrequick.html
this doesnt work and prints the entire line...how do i get it to
wordwise?
print map { /\b(\w+\s+$key\s+\w+)\b/, "\n" } @sspace;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>