Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: SImulation of an Inventory.

by ww (Archbishop)
on Jun 23, 2012 at 01:28 UTC ( #977918=note: print w/replies, xml ) Need Help??


in reply to SImulation of an Inventory.

Your script causes my perl (AS 5.14) to throw multiple messages... had you included use strict (as you should have), it would have filled the screen with your problems. But these are what you should have told us about, at a minimum, rather than tossing them into the "not working" garbage pile:

Unquoted string "easy" may clash with future reserved word at D:\_Perl +_\pl_test\977910.pl line 6. Unquoted string "hard" may clash with future reserved word at D:\_Perl +_\pl_test\977910.pl line 9. Found = in conditional, should be == at D:\_Perl_\pl_test\977910.pl li +ne 13. Unquoted string "easy" may clash with future reserved word at D:\_Perl +_\pl_test\977910.pl line 13. Unquoted string "hard" may clash with future reserved word at D:\_Perl +_\pl_test\977910.pl line 16. Found = in conditional, should be == at D:\_Perl_\pl_test\977910.pl li +ne 20. Found = in conditional, should be == at D:\_Perl_\pl_test\977910.pl li +ne 47. Name "main::RNG" used only once: possible typo at D:\_Perl_\pl_test\97 +7910.pl line 21. D:\_Perl_\pl_test\977910.pl syntax OK
  • = makes an assignment; you want == in your conditional to test for (numeric equality or -- in this case -- eq or a regex to test the alpha entry you invite.
  • BUT even when you correct your ifs, you still have work to do. The Monastery is rife with examples of collecting input, so with the exception of the implicit hint there, learning how to fix it is yours to do.
  • Among other things, just using a more idiomatic way to deal with input won't make your code "good;" you also need to add some error handling: what should your script do if the user merely hits enter when asked for a name?
  • The gotos are utterly unnecessary in this script. You can take them out and have execution simply fall thru from one named section to another.
  • Your lines 5-17 attempt to execute before a value is assigned to $diff. (Think reordering your code or stuffing those lines into a sub, called after the other input is received).

Try another iteration... show us how you solved these.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2021-02-26 13:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?