in reply to seeking advice on loops
Update: Warning! Spoiler (code) follows:
use Data::Dumper; my @order = (); my %dialogue = ( PN => 'Product Name', PR => 'Price', QU => 'Quantity', YN => 'Enter another order line (Y/N)' ); my @kd = sort keys %dialogue; # they happen to be in right order # else could prefix hash keys with digit +s my $response; do { # this loop style is 'do once then conditionally repeat' my %hash = (); foreach my $kd ( @kd ) { # n.b. nested loop print $dialogue{ $kd } . ": "; $response = <>; chop $response; $hash{ $kd } = $response; } delete $hash{ YN }; # remove last response (the Y/N) from hash push @order, \%hash; } while ( uc( $response ) eq 'Y' ); print Dumper( \@order );
-M
Free your mind
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: seeking advice on loops
by Michalis (Pilgrim) on Oct 07, 2005 at 12:08 UTC | |
by Moron (Curate) on Oct 07, 2005 at 12:28 UTC | |
by Michalis (Pilgrim) on Oct 07, 2005 at 12:39 UTC |