Click here to Skip to main content
15,887,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
str = File.open('rename.rb','w')
content = str.read
puts content
end



error at line 4
pls help
i'm a newbie
Posted

1 solution

Couple issues with this that I see, sorted hopefully in the order of interpreter failures:

1) You don't need that end. There's nothing opening it - no if, while, begin block, etc. 'kend' is the symbol for a lexicographical end - that is, an end written by the programmer. $end is the symbol that means end of file. Your error message is saying, "You typed end, but I'm expecting the end of the file." So delete line 4.

That MAY fix your problems; if not:

2) str (the File object for rename.rb) is opened for writing, but you're trying to read. Change line 1 to
VB
str = File.open('rename.rb','r')
Or you may get an IOError on that 'read' called on an object only opened for writing.

3) Depending on your version, you may have overwritten rename.rb and replaced it with an empty file, by opening it for writing. That can default to File.new(), and because the program ended without writing anything, it's a blank file.

Hope that helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900