Re: How to Read Files? [was: Re: learning perl 3rd vs 4th]

[email protected] ("Chas. Owens")
Newsgroups perl.beginners
Message-ID <[email protected]>
On Mon, May 26, 2008 at 1:29 AM, AndrewMcHorney <[email protected]> wrote:
> Hello
>
> The spec does not allow for carriage returns or line feeds making it a long
> line. Is there a way to read "x" number of bytes?
snip

Take a look at the the record separator ($/) variable*.  You can set
it to a reference to a number and it will cause the <> operator to
read that number of bytes:

$/ = \4096; #read 4k at a time
while (my $block = <>) {
    #do stuff with 4k block
}

* perldoc perlvar or http://perldoc.perl.org/perlvar.html#$/
-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.