On Wed, Aug 29, 2012 at 5:58 AM, Jam <[email protected]> wrote:
>
>
> On Aug 28, 2012, at 9:46 PM, Pepe Pew <[email protected]> wrote:
>
>> Hello, I need your help.
>> I just made the file "analyzer.rb" and placed on a folder.
>> This file has the code:
>>
>> line_count = 0
>> File.open("text.txt").each { |line| line_count += 1 }
>> puts line_count
>>
>> I tried to run it by CMD, but it doesn't oppened the "text.txt" file.
>> "analyzer.rb" and "text.txt" are on the same folder.
>
> it looks like you're executing the script from a different directory than it 
> exists in.

The important bit here is to execute the script from the directory
where text.txt sits since the path is hardcoded in the script.

Btw, in Ruby 1.9.3 you can do

line_count = File.foreach("text.txt").count

:-)

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to