in reply to Re^3: how to search for a string in a particular file?
in thread how to search for a string in a particular file?
#!/tools/packarch/public/perl/5.8.8/bin/perl use strict; use warnings; open(my $file, "<", "input.txt") or die "Can't open input.txt: $!"; my $string = "icecream"; while (<$file>) { if (/$string/) { print "found string $string\n"; } else { my $notfound = "not found"; } } if (my $notfound eq "not found") { print "string not found\n"; }
I'm seeing this error now: Use of uninitialized value in string eq at ./testScript.pl line 19, <$file> line 8.
What does this mean? the file input.txt does not contain the string "icecream" so ideally i should see the output at "string not found"
ps. thank you guys for all your help!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: how to search for a string in a particular file?
by roboticus (Chancellor) on May 29, 2012 at 18:56 UTC | |
by tm86 (Initiate) on May 30, 2012 at 04:31 UTC |