Re: Reading X lines at a time

2004-05-09 Thread A. Pagaltzis
* Rick Delaney [EMAIL PROTECTED] [2004-05-03 15:23]: while (my @a = map { eof() ? () : scalar } 1 .. $n) { print @a; print SEPARATOR\n; } while (my @a = grep defined, map scalar , 1 .. $n) { print @a; print SEPARATOR\n; } -- Regards,

Reading X lines at a time

2004-05-03 Thread Jose Alves de Castro
This has been bugging me for some time... What would be the easiest way to read X lines of input at a time? I don't really think you can use $/ for this, as it's not a regex, but a string... However, the thought of having to use more than one line of code to do this scares the hell out of me

Re: Reading X lines at a time

2004-05-03 Thread Dave Mitchell
On Mon, May 03, 2004 at 12:19:55PM +0200, Sven Neuhaus wrote: How about push @lines, scalar FILEHANDLE, 1..$X; I presume you meant push @lines, scalar FILEHANDLE for 1..$X; Technically however, you are still reading one byte at a time... No you're not! -- Thank God I'm an atheist.

Re: Reading X lines at a time

2004-05-03 Thread Jose Alves de Castro
I was thinking about something I could use HERE: while (HERE) { # do something with $_ } So it would take a little twist, probably... What about when you have $X - 1 lines to read? It works, right? On Mon, 2004-05-03 at 11:39, Dave Mitchell wrote: On Mon, May 03, 2004 at 12:19:55PM +0200,

Re: Reading X lines at a time

2004-05-03 Thread Georg Moritz
From the keyboard of Jose Alves de Castro [03.05.04,10:56]: This has been bugging me for some time... What would be the easiest way to read X lines of input at a time? I don't really think you can use $/ for this, as it's not a regex, but a string... However, the thought of having to use

Re: Reading X lines at a time

2004-05-03 Thread Georg Moritz
From the keyboard of Georg Moritz [03.05.04,13:37]: From the keyboard of Georg Moritz [03.05.04,13:34]: [..] $_=x$n silly me, it was not about n-ification.. :-/ @_=map{scalar()}(1..$X) -- _($_= x(15).?\n.q·/)Oo. G°\/ /\_¯/(q/

Re: Reading X lines at a time

2004-05-03 Thread Georg Moritz
Hello Jose, @_=map{scalar()}(1..$X) inside a loop testing for eof is necessary: while(!eof()(@_=map{scalar()}(1..$X)){ foo; # gets @_ } greets, georg -- _($_= x(15).?\n.q·/)Oo. G°\/ /\_¯/(q/ \__(m.·.(_(always

Re: Reading X lines at a time

2004-05-03 Thread Rick Delaney
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

Re: Reading X lines at a time

2004-05-03 Thread Georg Moritz
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

Re: Reading X lines at a time

2004-05-03 Thread Peter Makholm
Sven Neuhaus [EMAIL PROTECTED] writes: How about push @lines, scalar FILEHANDLE, 1..$X; If you want something that returns X lines in a way like FH does, then you could use a hack like: @lines = map scalarFH,1..$X -- Peter Makholm | I have no caps-lock but I must

Re: Reading X lines at a time

2004-05-03 Thread Jose Alves de Castro
On Mon, 2004-05-03 at 14:23, Rick Delaney wrote: print SEPARATOR\n; It's so weird when you're using a line of code and suddenly see it posted by someone else... :-) -- Jos Alves de Castro [EMAIL PROTECTED] Telbit - Tecnologias de Informao

Re: Reading X lines at a time

2004-05-03 Thread Peter Makholm
Georg Moritz [EMAIL PROTECTED] writes: $_=x$n or @_=x$n Neither of these works for me. I had the same thought but the x-operator is eager (of course) and only evaluate once and then copies the result giving you $n copies of the first line. -- Peter Makholm |The

Re: Reading X lines at a time

2004-05-03 Thread Rick Delaney
On Mon, May 03, 2004 at 03:27:01PM +0200, Georg Moritz wrote: From the keyboard of Rick Delaney [03.05.04,09:23]: while (my @a = map { eof() ? () : scalar } 1 .. $n) { print @a; print SEPARATOR\n; } but this will loop forever, since the array @a is always

Re: Reading X lines at a time

2004-05-03 Thread Georg Moritz
From the keyboard of Rick Delaney [03.05.04,09:42]: On Mon, May 03, 2004 at 03:27:01PM +0200, Georg Moritz wrote: From the keyboard of Rick Delaney [03.05.04,09:23]: while (my @a = map { eof() ? () : scalar } 1 .. $n) { print @a; print SEPARATOR\n; }

Re: Reading X lines at a time

2004-05-03 Thread Jose Alves de Castro
On Mon, 2004-05-03 at 14:23, Rick Delaney wrote: while (my @a = map { eof() ? () : scalar } 1 .. $n) { [...] } This seems to be what I was looking for... :-) Thanks :-) jac -- Jos Alves de Castro [EMAIL PROTECTED] Telbit - Tecnologias de Informao

Re: Reading X lines at a time

2004-05-03 Thread Uri Guttman
XN == Xavier Noria [EMAIL PROTECTED] writes: XN What about a foreach loop: XN use Perl6::Slurp; File::Slurp also supports $/ being a regex. XN $X = 4; XN $regexp = '.*\n?' x $X; XN foreach $Xlines (slurp 'foo.txt', { irs = qr/$regexp/ }) { XN # ...