From: Osuka Adartse Date: 2004-02-16T10:43:55+09:00 Subject: Re: problem with variables Dirk Einecke wrote: > Hi. > > I've a problem with variables. > I define a global variable outside a method and then I use this variable > in a method. And thats my problem. I can print the value of the variable > but in the line with the eval() the place holder (#{temp}) is not > replaced and the output is empty. But why. > > Can anybody help me? > > > #!/usr/bin/ruby > > $temp = "Hallo" > > def test() > puts $temp # -> Hallo ... all is okay > test = "#{temp} World" You're using a global var but here you're asignining a local var that is undefined(actually nil) and that's why, change line to: test = "#{$temp} World" > puts eval( '"' + test + '"' ) # -> ... nothing ... but why? > end > > print "Content-type: text/html\n\n" > print test() just use test() > > > bye > Dirk Einecke > After that change you'll get: Content-type: text/html Hallo Hallo World cheers Adartse