hi
i use the following syntax to read a file with 7 lines in a array
but only the first element contains all lines
i tryed to add a delimiter as 2. argument but it doesnt work?
code:
arFile = readlines(“datname”)
2. try
delimiter = "\n"
arFile = readlines(“datname”, delimiter)
this produces an error
···
–
thx
martin pfeffer
at
suse 9.0
Apache 2.0
http://eurowalker.is.dreaming.org
Received: Thu, 6 May 2004 19:28:56 +0900
And lo, Martin wrote:
hi
i use the following syntax to read a file with 7 lines in a array
but only the first element contains all lines
i tryed to add a delimiter as 2. argument but it doesnt work?
code:
arFile = readlines(“datname”)
2. try
delimiter = “\n”
arFile = readlines(“datname”, delimiter)
this produces an error
readlines() reads from STDIN until EOF. If you want to read from a file, you’ll want:
IO.readlines(“datname”)
Gregory Millam wrote:
Received: Thu, 6 May 2004 19:28:56 +0900
And lo, Martin wrote:
hi
i use the following syntax to read a file with 7 lines in a array
but only the first element contains all lines
i tryed to add a delimiter as 2. argument but it doesnt work?
code:
arFile = readlines(“datname”)
2. try
delimiter = “\n”
arFile = readlines(“datname”, delimiter)
this produces an error
readlines() reads from STDIN until EOF. If you want to read from a file, you’ll want:
IO.readlines(“datname”)
now i use this dirty workaround but it works
arFile = readlines(“tagedatei_uruz”)
arLines = arFile[0].split(“\n”)
···
–
thx
martin pfeffer
at
suse 9.0
Apache 2.0
http://eurowalker.is.dreaming.org
Martin Uruz wrote:
now i use this dirty workaround but it works
arFile = readlines(“tagedatei_uruz”)
arLines = arFile[0].split(“\n”)
Note that you’re calling Kernel::readlines. It’s one and only argument (if supplied) is the line separator.
Since you’re passing the file name, which presumably doesn’t appear anywhere in the file’s text, you get back an array containing one entry.
As Gregory suggested, I think you actually want something like
arLines = File.open(“tagedatei_uruz”).readlines
Actually, I’m surprised you get what you expect at all. I assume you’re running this via a command like
ruby yourscript.rb < tagedatei_uruz
which is why calling Kernel::readlines works.
Hope that helps.
Harry O.
Were you aware that you could do:
arFile = File.read(“tagedatei_uruz”)
arFile.each { |line|
… your code here
#each works on a single string
giving you each line
}
···
On Thursday, 6 May 2004 at 20:03:55 +0900, Martin Uruz wrote:
Gregory Millam wrote:
Received: Thu, 6 May 2004 19:28:56 +0900
And lo, Martin wrote:
now i use this dirty workaround but it works
arFile = readlines(“tagedatei_uruz”)
arLines = arFile[0].split(“\n”)
–
Jim Freeze
HOW YOU CAN TELL THAT IT’S GOING TO BE A ROTTEN DAY:
#1040 Your income tax refund cheque bounces.