Re: Reading X lines at a time

Georg Moritz <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
From the keyboard of Rick Delaney [03.05.04,09:23]:

> On Mon, May 03, 2004 at 02:07:42PM +0200, Georg Moritz wrote:
> > Hello Jose,
> >
> > > @_=map{scalar(<>)}(1..$X)
> >
> > inside a loop testing for eof is necessary:
> >
> > while(!eof()&&(@_=map{scalar(<>)}(1..$X)){
> >     &foo; # gets @_
> > }
>
> The eof() must be inside the map or things will be messed up when you
> don't have an exact multiple of $X lines.

you have some undefs in the resulting array.

>     while (my @a = map { eof() ? () : scalar <> } 1 .. $n) {
>         print @a;
>         print "SEPARATOR\n";
>     }

but this will loop forever, since the array @a is always defined, even
on eof(). map() will return a bunch of undefs.

greets,
georg

-- 
_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s,/,($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e,e && print}
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.