thanks so much for your input...I am almost done with this assignment and got thru the user input section...now I have to run a subroutine to print out the array and hashes...of course I have encountered a problem...

the assignment states to run a subroutine on the @item array and then go thru the two hashes (%qty and %price) and print out each value associated with the $itemname

so here is my code and I cannot get it to print out the associated values in the hashes that are associated with the $itemname key

#!/usr/bin/perl -w #cash register program my %qty=(); my %price=(); #####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 to capture customer information here##### my $continue='Y'; while ($continue eq 'Y'){ print "Please enter an item or product name\n"; chomp ($itemname = <STDIN>); push @item, $itemname; print "Please enter the quantity of the item\n"; chomp ($itemquantity = <STDIN>); $qty{$itemname} = $itemquantity; my @qty = values %qty; print "Please enter the price of the item\n"; chomp ($itemprice = <STDIN>); $price{$itemname} = $itemprice; @price=%price; my @price = values %price; print "Would you like to add another item? - Y or N\n"; chomp ($continue = <STDIN>); } ##### process information with a subroutine here ##### foreach $item (@item) { print "Item: $item\n"; print "@qty\n"; print "@price\n"; }

I am learning as I go thru this but I know it is a slow process for me - thanks for your advice monks


In reply to Re^4: 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.