Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: syntax error near else and }

by InfiniteSilence (Curate)
on Feb 04, 2012 at 23:57 UTC ( #951881=note: print w/replies, xml ) Need Help??

in reply to syntax error near else and }


  • You are using warnings but not strict. Add use strict to your code and watch what happens.
  • Lots and lots of nested if statements and the subsequent need to indent is normally a sign that you should strongly consider using subroutines and even a switch statement in your code.
  • I hate it when people post code with line numbers.
  • "Q" or "q" really won't make the input from STDIN quit...the CR does -- try:  perl -e 'print qq|Enter q or Q to quit|; ($list = <STDIN>);'
  • On the same subject, you could have done:   perl -e 'print qq|Give me 20 #s now dammit! |; ($list = <STDIN>); my @stuff = split q| |, $list; print scalar @stuff;'
    where you could have died if there were < 20 numbers entered: die 'not enough numbers!' unless (@stuff == 20);
  • This isn't very readable and you should be using eq instead: ...$work == ' ') . How many spaces is that -- 2 or 3? Since I cannot tell immediately I don't know. Try,  perl -e 'my $work = q~     ~; if ($work eq q| | x 5){print 1};'
    or perhaps a regex.
I recommend that you check to see if your code is on par with the other students in your class. If not then you might try and reread whatever material you were given. If it is look ahead in your materials to see if, near the end of the course, you will be expected to write terse, readable, working code. If not, consider leaving the class and getting your money back. Your time and money would be far better invested in a good book. There are recommendations available at

Celebrate Intellectual Diversity

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://951881]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2018-06-25 01:15 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.