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 }

In reply to syntax error near else and } by maitai091054

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.