faqts : Computers : Programming : Languages : Perl : Common Problems : File Handling

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

35 of 37 people (95%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How do I read an entire file as a string?

Sep 21st, 2003 10:30
Simon B, Per M Knutsen,


Clear $/ to allow the entire file to be read straight into your  
variable: 
$file = "include.dat"; 
my $string; 
{ 
   undef $/;        # read file all at once 
   open (FILE, $file) || die "cannot open $file: $!"; 
       $string = <FILE>; 
   close FILE; 
}