in reply to Re^2: Error using grep
in thread Error using grep
You need to show the actual code you tried. Much, much better is to rework your code into a stand alone test script so we can run exactly what you are running with the same data. Something like:
#!/usr/bin/perl use strict; use warnings; my $keyword = 'file'; # Search for the key pattern in the file information. while (defined (my $line = <DATA>)) { next if $line !~ /\b\Q$keyword\E\b/; print "Found key word $keyword on line $.\n"; exit; } print "Keyword not found\n"; __DATA__ Hi, I am a newbie to perl. I am trying to pass the filename and search + for a keyword in that file and if found print that line else print not found + message. However though my file has the keyword I get not found message.Please +help.I
Prints:
Found key word file on line 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Error using grep
by justkar4u (Novice) on Mar 29, 2011 at 18:13 UTC | |
by GrandFather (Saint) on Mar 29, 2011 at 20:06 UTC | |
by justkar4u (Novice) on Mar 29, 2011 at 23:00 UTC |