in reply to Befuddled by The Llama

As others stated ... it seems you want to let the user type something in, but nowhere do you provide the place to do it! Since you seem to be using this approach (getting user input, even when it's not really necessary for the problem), and since it seems to be the same design each time (with error introduced, albeit), I'd suggest adhering to the 'Lazy' virtue of a perl programmer and go ahead and write some functions for all this input junk and just reuse the stuff time in and time out. Immediately, you might try (although this doesn't provide the massive cleanup necessary to make it look decent),
$in[$count] = <STDIN>; while ($in[$count] !~ /q/i { print "\nPlease enter a number: "; chomp($in[$count]"; count++; $in[$count] = <STDIN>; }

Replies are listed 'Best First'.
Re: Re: Befuddled by The Llama
by parv (Parson) on May 31, 2004 at 00:40 UTC

    The given situation is perfect for a do-while loop to avoid the need to read from stdin in more than one place...

    { my $count = 0; do { print "\nPlease enter a number: "; $in[$count++] = <STDIN>; } while ( $in[-1] !~ m/q/i ); pop @in; # Remove 'quit signal' } chomp @in;

    ...but i would personally prefer something like...

    while ( 'reading...' ) { print "\nPlease enter a number: "; my $in = <STDIN>; do { push @in , $in; next; } unless $in =~ m/q/i; last; } chomp @in;
Re: Re: Befuddled by The Llama
by TomDLux (Vicar) on May 31, 2004 at 00:35 UTC

    I would suggest getting input BEFORE doing the chomp .... and since you want this to happen at least once, it is the ideal situation for using do{} while();. Note that this requires moving the increment.

    do { print "\nPlease enter a number: "; $in[$count] = <STDIN>; chomp($in[$count]"; } while ($in[$count++] !~ /q/i

    --
    TTTATCGGTCGTTATATAGATGTTTGCA