in reply to Re^3: seeking advice on loops
in thread seeking advice on loops
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
|
|---|