in reply to Re: How do I read an entire file into a variable?
in thread How do I read an entire file into a variable?

Its very old for you. But i am very new to perl. So i am trying the existing programs which solved here. When i tried the above program i commented the two if cases

# seach for your text ... if ($myfile =~ m/some txt i look for/) { print "Found the text\n"; } # and look for more text if ($myfile =~ m/some other text i look/) { print "Got other text\n"; }

and in the last i printed the variable like this.

 print $myfile,"\n";

As per the question the variable contain the total file in that variable. But its printing only one line. Please give some clarity where i missing

Replies are listed 'Best First'.
Re^3: How do I read an entire file into a variable?
by Anonymous Monk on Aug 25, 2015 at 06:25 UTC

    Hi ravi45722 , this is how its done :) with Path::Tiny

    use Path::Tiny qw/ path /; my $myfile = path( '/home/me/myfile' )->slurp_raw;

    See reading an entire file into memory, however big it might be, is commonly called "slurp"ing

    You can also read about it perlintro and free book Modern Perl