use strict; use warnings; my $input_file='file.txt'; while (1){ # Infinite loop print "Enter the word you are looking for (or 'quit' to exit): "; my $answer = <STDIN>; chomp $answer; # remove newline char from answer last if $answer =~/quit/i; # Exit loop print "Looking for '$answer'\n"; my $found = 0; open my $f, "<", $input_file or die "ERROR: Cannot open $input_file + : $!"; while (<$f>) { m/$answer/ or next; $found=1; last; } close $f; if ($found){ print "Found $answer!\n"; }else{ print "Sorry - $answer was not found\n"; } }
...Disinformation is not as good as datinformation. Don't document the program; program the document.
In reply to Re: How to read the file from stdin using perl?
by NetWallah
in thread How to read the file from stdin using perl?
by gopikavi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |