maitai091054 has asked for the wisdom of the Perl Monks concerning the following question:
I am new to Perl and taking a class. I am getting the following errors: syntax error at ./B16a line 44, near "else", syntax error at ./B16a line 54, near "}"
I have matched up all {} and they seem fine and to me the else looks fine as well. Any assistance would be appreciated.
1 #!/usr/bin/perl 2 3 use warnings; 4 5 print "Enter numbers from 1 to 20 and/or letters seperated by a sp +ace:", "\n "; 6 print "Enter q or Q to quit", "\n"; 7 ($list = <STDIN>); 8 chomp $list; 9 print $list, "\n"; 10 print "length of list: " , length($list), "\n"; 11 $howlong = length($list); 12 print "howlong = ", $howlong, "\n"; 13 $sum = 0; 14 $pointer = 0; 15 $hold = ""; 16 $work = ""; 17 while (!$flag and $pointer <= $howlong +1) 18 { 19 $work = substr($list,$pointer,1); 20 if ($work eq "q" or $work eq "Q") { 21 $flag = true; 22 print "flag = , $flag, ", "\n"; 23 } 24 if ($work ne "q" and $work ne "Q") { 25 if ( $work =~ /^[\+-]*[0-9]*\.*[0-9]*$/ && $work !~ /^[\. ]*$/ + ) { 26 if ($work == ' ') { 27 if ($pointer > 0) { 28 $hold = "$hold"." + "."$work"; 29 print "pointer = ", $pointer, "\n"; 30 print "hold = ", $hold, "\n"; 31 print "work = ", $work, "\n"; 32 $sum = $sum + $work; 33 $pointer++; 34 } 35 else { 36 $hold = "$hold"."$work"; 37 $sum = ($sum + $work); 38 $pointer++; 39 } 40 } 41 else { 42 $hold = $hold.$hold; 43 } 44 else { 45 $pointer++; 46 print "has alpha: ", $work, "\n"; 47 } 48 } 49 else { 50 print ($hold, " = ", $sum, "\n"); 51 } 52 53 } 54 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: syntax error near else and }
by InfiniteSilence (Curate) on Feb 04, 2012 at 23:57 UTC | |
|
Re: syntax error near else and }
by choroba (Cardinal) on Feb 04, 2012 at 23:18 UTC | |
by Generoso (Prior) on Feb 05, 2012 at 00:45 UTC | |
by choroba (Cardinal) on Feb 05, 2012 at 11:23 UTC | |
by maitai091054 (Initiate) on Feb 05, 2012 at 23:10 UTC | |
by choroba (Cardinal) on Feb 05, 2012 at 23:19 UTC |