Dumb mistake in 11-line script; any insights?

R

RichardOnRails

Hi,

I have the 11-line script below. Ruby 1.9.3 barfs on line 8 with the
error msg in the comment on that line.

Script
=====
print "Search what: D = Docs; C = Current
what = gets.chomp
wk_dir = case what
when /^[Dd]/
Dir.chdir ".."
Dir.pwd
when /^[Cc]/
"K:\\___Current" # syntax error, unexpected tCONSTANT, expecting
$end
else
puts "Invalid choice \"%s\"" % what && exit
end
 
R

RichardOnRails

                                           ^ Missing "

Thanks, Christian. It's strange that the missing quote didn't cause a
syntax error on earlier statements.
 
R

RichardOnRails

Multi-line strings are no problem in Ruby:

string = "that spans
multiple
lines"

I'd recommend you to get an editor with smart indentation (or syntax
highlighting, if you prefer).  It will discover such errors quickly.

Thanks for your additional advice. I use SciTE, which fortunately
provides syntax coloring. I did notice some odd coloring but didn't
notice anything wrong and mistakenly focused on the code lower down.
I was just too sloppy.

Again, thank you,
Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top