Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: New Perl user - help with my homework

by haj (Vicar)
on Dec 24, 2018 at 11:55 UTC ( [id://1227653]=note: print w/replies, xml ) Need Help??


in reply to New Perl user - help with my homework

I'll not comment on the errors in the algorithm - after all, it's your homework and not mine. So, here are some Perl tips:

  • Read your variable like this:
    print "Please enter a number: \n"; my $limit= <STDIN>; chomp $limit;
    Note there are no parentheses around $limit in the declaration. With the parentheses, you enter "list context" - which means you'll read line after line from STDIN, until you hit Ctrl-D for "end of file".
  • Every statement ends with a semicolon; this is missing in your line $sum += 2. That's why you get a syntax error.
  • If your output should contain the phrase (1+3+5), then take a look at the join function. It should give you a hint what to push into your @array.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 15:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found