T
Trochalakis Christos
Hello there,
I wan't to extract all the words from a file and so i wrote the
following code:
file = ARGV[0]
File.open('output','w') {|f|
IO.read(file).scan(/\w+/).each{|w| f.print w}
}
The problem with this code is that it stores all the words in an array
which is not so good in terms of efficiency.
Is there a better way to do it?
Something like IO.read(file).each_scan { foo }
Thanks
Christos
I wan't to extract all the words from a file and so i wrote the
following code:
file = ARGV[0]
File.open('output','w') {|f|
IO.read(file).scan(/\w+/).each{|w| f.print w}
}
The problem with this code is that it stores all the words in an array
which is not so good in terms of efficiency.
Is there a better way to do it?
Something like IO.read(file).each_scan { foo }
Thanks
Christos