in reply to Re: seeking advice on loops
in thread seeking advice on loops
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: seeking advice on loops
by Tanktalus (Canon) on Oct 09, 2005 at 01:48 UTC | |
by sierrastar (Sexton) on Oct 10, 2005 at 00:05 UTC | |
by sierrastar (Sexton) on Oct 10, 2005 at 00:33 UTC | |
by Tanktalus (Canon) on Oct 10, 2005 at 14:56 UTC | |
by sierrastar (Sexton) on Oct 10, 2005 at 19:08 UTC | |
by Tanktalus (Canon) on Oct 10, 2005 at 22:43 UTC | |
|