Hello gopikavi,
I am bit confused as the rest of the monks.
Do you mean that you want something like that? Reading STDIN and if exists inside your file while print the whole file?
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $| = 1; # turn on autoflush my $file = 'file.txt'; open my $fh, "<", $file or die "Could not open '$file': $!"; chomp(my @files = <$fh>); close $fh or die "Coould not close '$file' $!"; while (my $stdin = <>) { chomp $stdin; last if $stdin eq ""; if ( grep { $stdin eq $_ } @files ) { print Dumper \@files; } else { print "There is no word in the $file\n"; } } __DATA__ $ perl file.pl data1 $VAR1 = [ 'data1', 'data2', 'data3', 'data4' ]; DATA1 There is no word in the file.txt
Update: Adding last if $stdin eq ""; to exit loop.
In reply to Re: How to read the file from stdin using perl?
by thanos1983
in thread How to read the file from stdin using perl?
by gopikavi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |