Re: the file slurping is not working

2009-06-10 Thread Smylers
Tom Christiansen writes:

 Larry wrote:
 
  But we're trying very hard to get rid of most such special cases in
  Perl 6.  Usually we can get the recommended Perl 6 code to just DWYM
  as a fallout of the general semantics,
 
 Oh.  You mean like for directories containing a file whose name is the
 1-char string, 0, and that file pre-emptively terminating a readdir
 loop the way it used to.

I can't find it in the spec (link anybody?) but I'd expect the return
value to be something which stringifies to 0 but boolifies to false,
meaning it won't terminate the loop.

That way we get the intuitive behaviour, but don't need a special case.
And the general mechanism used to make this work is something available
for all Perl programs to take advantage of, not an exception that
requires baking into the core language internals.

Smylers


Re: the file slurping is not working

2009-06-05 Thread Aruna Goke

Carl Mäsak wrote:

Aruna ():

I tested the below code on parrot-1.1.0 and it read all the lines in the
file and tested same code on the latest git update (4th June 2009), it
outputs only the first line.


That's what C$file.get does -- it gives you one line per default.
You want C$file.lines.

// Carl


Thanks.



Re: the file slurping is not working

2009-06-05 Thread Daniel Carrera

Carl Mäsak wrote:

Aruna ():

I tested the below code on parrot-1.1.0 and it read all the lines in the
file and tested same code on the latest git update (4th June 2009), it
outputs only the first line.


That's what C$file.get does -- it gives you one line per default.
You want C$file.lines.


Then why is it that .get works fine for $*IN?

while $*IN.get - $line {
say $line
}



Re: the file slurping is not working

2009-06-05 Thread Leon Timmermans

 Then why is it that .get works fine for $*IN?

 while $*IN.get - $line {
        say $line
 }


Because you're using a while loop instead of a for loop ;-)

Leon


Re: the file slurping is not working

2009-06-05 Thread Daniel Carrera

Leon Timmermans wrote:

Then why is it that .get works fine for $*IN?

while $*IN.get - $line {
   say $line
}



Because you're using a while loop instead of a for loop ;-)


Worse. The code I wrote has a subtle but horrible error. The condition 
will fail as soon as you hit a blank line!!


Daniel.


Re: the file slurping is not working

2009-06-05 Thread Carl Mäsak
Daniel (), Leon (), Daniel ():
 Then why is it that .get works fine for $*IN?

 while $*IN.get - $line {
       say $line
 }


 Because you're using a while loop instead of a for loop ;-)

 Worse. The code I wrote has a subtle but horrible error. The condition will
 fail as soon as you hit a blank line!!

Which, I think, summarizes why the 'for $*IN.lines' idiom is preferred
in Perl 6.

// Carl