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.
In Section
Seekers of Perl Wisdom