* 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,
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
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.
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,
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
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/
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
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
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
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
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
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
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
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;
}
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
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 # ...
16 matches
Mail list logo