On Mon, 19 Oct 2015 19:48:06 +0530 Prashant Thorat <thorat.prash...@gmail.com> wrote:
> Hi All, > > I have a file with multiple lines ,I want to assign all content to > variable & then want to work on it. > Like want to match pattern /window/ from it. > how can it is possible ? > for example - > > open ( F1 ,"file.txt") || die "$!"; > > $a=<F1>; > > if (/window/i){print > "it is present\n"; > } use autodie; # dies when I/O error occurs my $file = 'file.txt'; # write literals once so they are easy # to find and change my $contents = ''; # holds contents of $file # use a block to isolate the INPUT_RECORD_SEPARATOR { local $/; # file slurp mode open my $fh, '<', $file; # three-argument open $contents = <$fh>; # slurps the whole file into $contents close $fh; # in case of input error, # give it a chance to report } if( $contents =~ /window/i ){ print "it is present\n"; } # see `perldoc perlvar` and search for /INPUT_RECORD_SEPARATOR # http://perldoc.perl.org/perlvar.html -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/