Multiline runaway??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • splatt
    New Member
    • Oct 2006
    • 2

    Multiline runaway??

    I'm getting this error on my program and don't know what's the problem?

    syntax error at testing5 line 38, near "chomp($choice= <STDIN>);"
    (Might be a runaway multi-line )) string starting on line 37)

    Here is the code:

    line34 until ($choice == q) {print "What would you like to convert?\n\n"};
    line35 chomp($choice=< STDIN>);

    line37 if ($choice == 1) {$choice = ($choice - 32) * 5/9;
    line38 print "Converts to $choice Celsius.\n\n";}
  • vssp
    Contributor
    • Jul 2006
    • 268

    #2
    I think STDN varilabel value set as NULL may be


    Please chsk
    vssp

    Comment

    • miller
      Recognized Expert Top Contributor
      • Oct 2006
      • 1086

      #3
      The flaw is simply in your logic. Line 34 displayed below is an infinite loop.
      Code:
      line34  until ($choice == q) {print "What would you like to convert?\n\n"};
      Change your code to
      Code:
      for (;;) {
      	print "What would you like to convert?\n\n";
      	chomp($choice=<STDIN>);
      	last if $choice eq 'q';
      
      	... # All your other code here
      }
      Last edited by miller; Oct 30 '06, 08:06 PM. Reason: Made more explicit

      Comment

      • splatt
        New Member
        • Oct 2006
        • 2

        #4
        Thanks for the reply. I've tried to approach from another angle but now I'm getting syntax errors:

        syntax error at testing8 line 39, near ")
        do fahrenheit"
        testing8 had compilation errors.


        code:

        print "What would you like to convert?\n\n";
        chomp($choice=< STDIN>);

        if ($choice eq '1')
        do fahrenheit();

        elsif ($choice == '2')
        do gallons();

        elsif ($choice == 3); {&miles;}

        elsif ($choice == 4); {&yards;}

        elsif ($choice == 5); {&feet;}


        sub code:
        sub fahrenheit{
        print "Enter the number you would like to convert?\n\n";
        chomp($choice=< STDIN>);
        $choice = ($choice - 32) * 5/9;
        print "Converts to $choice Celsius.\n\n"; }

        sub gallons
        {print "Enter the number you would like to convert?\n\n";
        chomp($choice=< STDIN>);
        $choice = $choice * 3.785;
        print "Converts to $choice liters.\n\n";}

        I've tried this so many ways that I can't see straight. Any guidance would be greatly appreciated.

        Comment

        • miller
          Recognized Expert Top Contributor
          • Oct 2006
          • 1086

          #5
          Originally posted by splatt
          .. but now I'm getting syntax errors:

          syntax error at testing8 line 39, near ")
          do fahrenheit"
          testing8 had compilation errors.
          Just like your error reported, the code that you tried was illegal. This line needs to be changed. Simply remove the "do", as there is no reason for it to be there. Also, you should follow the same design standards that you use for all other if statements by using code blocks {}.

          Code:
          do fahrenheit();

          Comment

          Working...