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:

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>);
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.