Four problems. (Aside from not previewing your node. Use <c>...</c> around code in your nodes.)
You call your file handle TABLE, table and IN. The name is case-sensitive, and using the wrong name obviously won't work. Furthermore, you're better off using lexical file handles:
open(my $fh, '<', $inputs) or die ... while (<$fh>) { ... } close($fh); # Optional.
Similarly, you read each line into $line, yet you use $_ further on.
Third, keep in mind that the lines returned by the <HANDLE> operator include a trailing newline. Use chomp($line); as the first line of the while loop if you wish to remove this newline.
Finally, you treat $string as if it's a regexp while it's probably just text. (Added for clarification: If $string contains text as opposed to a regexp, you can convert the text to a regexp using \Q...\E or quotemeta. )
if ($line =~ /\Q$string\E/) { ... }
If you want to check for equality:
if ($line eq $string) { ... }
In reply to Re: Searching through a file
by ikegami
in thread Searching through a file
by marco.shaw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |