I assume this is still the same homework assignment - I see some progress here. Going through it... there is nothing in the "set up hashes" section. That seems odd. We'll get back to that. And you're missing "use strict". You're using "-w" instead of "use warnings" which is ok, but not advised. Use "use warnings" instead, unless your teacher/professor is telling you otherwise (in that case, pass the course, but switch to this style afterwards).
In the user input section, you have some interesting indentation. I find the extra space in front of the chomps to be distracting and would encourage you to discard them. However, that said, whitespace is a good thing - you could put a blank line between the first print/chomp and the second:
The loop section starts with an undeclared $continue variable. Using strict would have caught this. You probably mean to have a "my " in front of this.print "Please enter your first and last name\n"; chomp (my $name = <STDIN>); print "Please enter your state sales tax in percentage\n"; chomp (my $tax = <STDIN>);
Inside the loop, we have more of this inconsistant indentation scheme. Indentation doesn't mean a thing to perl. It means a lot to the human reader who is unfamiliar with your work - which may be you 6 months from now, but, of a more immediate nature, will be your teacher/professor in a few days. Easy to read == easy to mark ;-)
Inside here we see that you create a new %qty hash and a new %price hash (using "my"). You probably intended that the "my %qty" and "my %hash" declarations to go into the hash initialisation section above. (I told you we'd get back to it.) Also, when you assign to an entire hash, such as when you say %qty = ( $itemname => $itemquantity );, you're removing anything that was already there and inserting the new hash (list) in its place. In this case, there's nothing there because you're creating a new hash each time, but we just talked about fixing that, so you would encounter this secondary problem. The syntax you're looking for is $qty{$itemname} = $itemquantity;. This will single out a single element of the hash, and set its value, regardless of whether it was there previously or not.
Of really minor importance at this point is the final question - "Would you like to add more item(s)?" First, you may really mean "Would you like ot add another item?" I just like getting rid of "(s)"s any time I see them. And you don't check that the value typed in is what you want to allow. If I type in "y", you're not going to continue, for example. Or if I type in "Yes, I really do." Or "wallace and grommit". But that's probably not a big deal at this stage of your course - you'll be able to address that in the future once you get the rest of the assignment finished ;-)
Good luck!
In reply to Re^3: seeking advice on loops
by Tanktalus
in thread seeking advice on loops
by sierrastar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |