Perl monks...I have been working on this for awhile now on my own... I am totally new to Perl and programming so I really appreciate your time

I put some print tags in the code to see if I was adding to each hash correctly, however, it seems to only hold the current key-value pair. I realize this code is not streamlined or as efficient as the monks would code it - but I am just learning - once again thanks for your advice

So two questions: why are my keys not assigning the actual value of $itemname?

why isnt the hash(es) keeping all the key-value pairs? I have to have a separate hash for quantity and price (that is part of the assignment)

of course I will continue to seek answers on my own

#!/usr/bin/perl -w #cash register program #retreive date and time ########set up hashes########## ##############User input here####### 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>); ####enter loop here####### $continue='Y'; while ($continue eq 'Y'){ print "Please enter an item or product name\n"; chomp ($itemname = <STDIN>); push @item, $itemname; print "@item\n"; print "Please enter the quantity of the item\n"; chomp ($itemquantity = <STDIN>); my %qty = ("$itemname" => $itemquantity); @qty=keys(%qty); print "@qty\n"; print "Please enter the price of the item\n"; chomp ($itemprice = <STDIN>); my %price = ("$itemname" => $itemprice); @price=keys(%price); print "@price\n"; print "Would you like to add more item(s)? - Y or N\n"; chomp ($continue = <STDIN>); }

thanks - sierra


In reply to Re^2: seeking advice on loops by sierrastar
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.