Professional Web Applications Themes

problem with variables - Ruby

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? <code> #!/usr/bin/ruby $temp = "Hallo" def test() puts $temp # -> Hallo ... all is okay test = "#{temp} World" puts eval( '"' + test + '"' ) # -> ... nothing ... but why? end print "Content-type: text/html\n\n" print ...

  1. #1

    Default problem with variables

    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?

    <code>
    #!/usr/bin/ruby

    $temp = "Hallo"

    def test()
    puts $temp # -> Hallo ... all is okay
    test = "#{temp} World"
    puts eval( '"' + test + '"' ) # -> ... nothing ... but why?
    end

    print "Content-type: text/html\n\n"
    print test()
    </code>

    bye
    Dirk Einecke
    Dirk Guest

  2. #2

    Default Re: problem with variables

    "Dirk Einecke" <de> wrote in message
    news:c0or2a$19s6c2$news.uni-berlin.de... 

    test = "#{$temp} World"


    Sean Guest

  3. #3

    Default Re: problem with variables

    Dirk Einecke wrote:
     
    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" 
    just use test() 
    After that change you'll get:

    Content-type: text/html

    Hallo
    Hallo World

    cheers
    Adartse


    Osuka Guest

  4. #4

    Default Re: problem with variables

    test = "#{temp} World"

    should be:

    test = "#{$temp} World"

    JA
    John Guest

  5. #5

    Default Re: problem with variables

    Hi.
     
    >
    >
    > test = "#{$temp} World"[/ref]

    Thanks to all (Sean Ross, Osuka Adartse, John Andrews).
    I works. :)

    bye
    Dirk Einecke
    Dirk Guest

Similar Threads

  1. loading variables from php problem
    By Craig White in forum Macromedia Flash Data Integration
    Replies: 1
    Last Post: March 10th, 09:48 PM
  2. Problem with Session Variables
    By Gomba in forum Macromedia ColdFusion
    Replies: 0
    Last Post: April 1st, 01:16 PM
  3. Problem with SESSION variables...
    By ZoombyWoof in forum PHP Development
    Replies: 18
    Last Post: November 4th, 11:08 PM
  4. A problem with variables?
    By Tuuska in forum PHP Development
    Replies: 3
    Last Post: August 6th, 03:50 AM
  5. Problem setting variables.
    By Jason Martyn in forum PHP Development
    Replies: 0
    Last Post: July 28th, 04:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139