From: Henrik Horneber Date: 2004-09-14T17:52:49+09:00 Subject: Re: Catching undefined global variable errors George Moschovitis wrote: > Hello everyone, > > have a look the following surprising code: > > $the_key = "ley1" # a common orthographic error > > a = { "key1" => 1, "key2" => 2} > > unless a[$the_key] > # ruby doesnt catch this error > puts "SURPRISE!!" > end > > Is there a way to catch such orthographic errors (and save > valueable debugging time)? I expected that the interpreter > would raise an Exception (undefined global or something) for > this code. > Hi! Well, the global _is_ defined. The orthographic error is in the value, not the variable name. How should the compiler/interpreter know what you plan to do with your keys for the hash? :) regards, Henrik