Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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 }

Problems:

  • 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 Perl.com.

Celebrate Intellectual Diversity


Comment on Re: syntax error near else and }
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://951881]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2014-07-29 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (228 votes), past polls