<?xml version="1.0" encoding="windows-1252"?>
<node id="522791" title="How can you sysread an entire file?" created="2006-01-12 14:51:24" updated="2006-01-12 09:51:24">
<type id="115">
perlquestion</type>
<author id="520200">
NeilF</author>
<data>
<field name="doctext">
Other than reading for a very long length (beyond the length that a file could ever be) what is the best way to read in a file. In my case the file could be anywhere upto around 1-5 meg big!&lt;BR&gt;
&lt;BR&gt;
This works, but is obviously not great:-&lt;BR&gt;
&lt;code&gt;
	my $rec;
	sysopen(DF, "test.txt", O_RDONLY);
	sysread DF, $rec, 26214400;	#25meg
	close DF;
&lt;/code&gt;
&lt;BR&gt;
One further question, if that variable ($rec) has thousands of records which end in CR, what's the best way to split it up into an array (retaining the carriage returns)? ie: Anything better than simply doing this after the read?&lt;BR&gt;
&lt;BR&gt;
&lt;code&gt;
	foreach(split("\n",$rec)){push(@array,"$_\n";)}
	$rec='';	# Release memory
&lt;/code&gt;
&lt;BR&gt;
Could it be cleverly combined into the read itself therefore meaning you don't have to use $rec and @array, and instead you could read it (ready split) straight into @array?</field>
</data>
</node>
