sorry I posted twice - I thought I lost the last post - thanks for all your input....the final thing I must do is to print the user input by running a subroutine thru @item and %qty and %price (print item name, quanity, and price)
I am having trouble figuring out how to run thru one array and two hashes in the same subroutine...
I tried a foreach statement for each one - but that did not work or seem to make sense. I have been trying to figure this our for hours now...
<any advice on the best way to grab the $itemname from @items and the value from %qty and %price that is associated with the $itemname (the key)? Here is my code so far...thanks monks.#!/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; ### 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"; while ( ($key, $value) = each %qty) { print "Quantity: $value\n"; } }
In reply to Re^4: seeking advice on loops
by sierrastar
in thread seeking advice on loops
by sierrastar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |