in reply to seeking advice on loops

The biggest potential source of confusion in this problem is that there are actually two loops being asked for - one where the user enters each field of the order line and one where he enters successive order lines.

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
    I appreciate original posters' honesty.

    He made clear that it's for a homework exercise, and he made clear that he was looking for advice. Many others have offered advice without offering code.
    I beleive you are wrong offering code. The OP probably wishes to try to write it himself (code-wise and not analysis-wise).

    Obviously, your code is good and I beleive that you wrote it with good intentions, and would be extremely helpful after the OP has delivered his homework, but at this time I think you should remove it, as a favor to the original poster (if he hasn't read that already).
    --
    Michalis
      Fair point - I have now put readmore tags around it and a warning.

      -M

      Free your mind

        Great! That's the best solution I think (and the one I would like been offered to me if I was the original poster).
        --
        Michalis