« Return to Thread: Source.fromFile(file).getLines

RE: Source.fromFile(file).getLines

by Detering Dirk-2 :: Rate this Message:

Reply to Author | View in Thread

Thanks Josh,

> As I mentioned before, we're trying something in the
> Scalax.IO-2.8.0 branch to allow specifying line endings, but
> using default parameters to "handle the most usual case"

BTW: I felt annoyed by Java's File notion and thought about
an alternative based on DirEntry, Dir and File.

Did a quick look into the repos and was glad to find
Location, Directory and File there, which seems to fit
into the same paradigm.

KR
Det


>
> - Josh
>
>
>
>
> On Fri, Jul 10, 2009 at 5:21 AM, Detering Dirk
> <Dirk.Detering@...> wrote:
>
>
> Sorry, I'm feeling a bit confused now ...
>
> I thought that "\n" is a "line terminator", (at least the
> one on *nix based systems).
>
> So I would translate your sentence
>
>
> > How would you tell apart a line that ends in "\n" with one
> > that doesn't?
>
>
> Into "How would you tell apart a line that ends in a line end
>
> with one that doesn't?"
>
>
> I now ask: How would tell that a stream of characters
> is a "line"
> if not by the line end marker? (Beside eof/eos of course).
>
>
> > The method getLines doesn't strip away any characters
> present in
> > the file. Which, by the way, is pretty  standard behavior.
>
>
> So far ...
>
>
> > In Perl, for instance, you need to "chomp"
> > away newlines if you don't want them. Likewise, in Scala, you
> > need to stripLineEnd newlines if you don't want them.
>
>
> ... so bad. Think of the regex pattern match problem
> discussed earlier
> here. (You have to strip the line before matching with
> "^some$" or
> use "(?s)^some$").
>
> From a domain progger's view:
>
> When reading a CSV file into excel I get the data into cells,
> without the cell separator (the C in CSV).
>
> So when calling getLine() I would expect to get the
> "line" without
> the technical EOL detail. This may be added again if I write
> "line" out to some file with write[Line|ln] or print[Line|ln],
> like I get the comma again when exporting the data as CSV.
>
> Same is true for every envelope data on underlying transport
> layers. They are only present on that layer.
>
> Looking at a stream from a char perspective I would
> expect to see it.
> Looking at it from a line perspective, it makes no sense to me.
>
> Just my 2ct.
>
>
> >
> >
> > On Thu, Jul 9, 2009 at 2:07 PM, Ricky Clarkson
> > <ricky.clarkson@...> wrote:
> >
> >
> >       ricky@ricky-desktop:~$ cat test.scala
> >       import scala.io.Source
> >       import java.io.File
> >
> >       object Main {
> >              def main(args: Array[String]) {
> >                      for (line <- Source.fromFile(new
> > File("test.scala")).getLines)
> >                              print("("+line+")")
> >              }
> >       }
> >
> >
> >       ricky@ricky-desktop:~$ scalac test.scala
> >       ricky@ricky-desktop:~$ scala Main
> >       (import scala.io.Source
> >       )(import java.io.File
> >       )(
> >       )(object Main {
> >       )(      def main(args: Array[String]) {
> >       )(              for (line <- Source.fromFile(new
> > File("test.scala")).getLines)
> >       )(                      print("("+line+")")
> >       )(      }
> >       )(}
> >       )(
> >       )(
> >       )
> >
> >       Note that I used print instead of println.  I can't
> > imagine it's a
> >       good thing to have line contain a line
> terminator of any kind.
> >
> >       2009/7/9 Daniel Sobral <dcsobral@...>:
> >
> >       > No, not expected. I don't get that either. Try doing
> > map(_ map(_ toInt)) to
> >       > the result of getLines. Maybe you are getting "\r\n"
> > and confusing it with
> >       > "\n\n".
> >       >
> >       > On Thu, Jul 9, 2009 at 1:38 PM, Gilles SCOUVART
> > <Gilles.SCOUVART@...>
> >       > wrote:
> >       >>
> >       >> Hello all,
> >       >>
> >       >> I was surprised to notice that using
> > Source.fromFile(file).getLines on a
> >       >> file with empty lines, those were added to the
> > previous non empty line.
> >       >> I.e. if the file contains this:
> >       >> ------
> >       >> test
> >       >>
> >       >>
> >       >> ------
> >       >> then getLines.next would return "test\n\n" (written
> > java-echap-style).
> >       >> I expected it would iterate on three lines instead:
> > "test", "", and "".
> >       >> This is a little bit annoying for pattern matching
> > on full lines...
> >       >>
> >       >> Is this expected behaviour?
> >       >>
> >       >> Gilles Scouvart.
> >       >
> >       >
> >       > --
> >       > Daniel C. Sobral
> >       >
> >       > Something I learned in academia: there are three
> > kinds of academic reviews:
> >       > review by name, review by reference and
> review by value.
> >       >
> >
> >
> >
> >
> >       --
> >       Ricky Clarkson
> >       Java Programmer, AD Holdings
> >       +44 1565 770804
> >       Skype: ricky_clarkson
> >       Google Talk: ricky.clarkson@...
> >
> >
> >
> >
> >
> > --
> > Daniel C. Sobral
> >
> > Something I learned in academia: there are three kinds of
> > academic reviews: review by name, review by reference and
> > review by value.
> >
> >
>
>
>
>

 « Return to Thread: Source.fromFile(file).getLines