Walt Mankowski on Wed, 2 May 2001 14:04:49 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Quick question: how to slurp a file?


On Wed, May 02, 2001 at 01:54:06PM -0400, Kyle R . Burton wrote:
> open FILE, "<file.txt" or die "error opening file.txt: $!\n";
> my $data;  {local$/=undef;$data=<FILE>;}
> close FILE;

You can also read in the entire file at once by assigning <> to an
array.  This reads the whole file into the array at once, with each
array element holding one line of the file:

my @whole_file = <FH>;
foreach my $line (@whole_file) {
	<do something with $line>
}

-- 
Walter C. Mankowski
Senior Software Engineer	Myxa Corporation
phone: (610) 234-2626		fax: (610) 234-2640
email: walt@myxa.com		http://www.myxa.com

**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**