in reply to Ending user input

To stop asking for more user input after the word 'done' has been entered, you may simply put <STDIN> inside a loop containing also a conditional (for exit):
use strict; # never go by without it! ;) rint "Enter your data and then it will print out in reverse order.\n"; my @input; while (<STDIN>){ chomp; last if m/done/i; # quit this loop if input # matches (case insensitive) the word 'done'. push @input, $_; # otherwise, add the word to the list } # Use 'for' loop instead of while if you need to # access array elements via an index variable. for (my $currentline = 1; $currentline <= scalar @input; $currentline +++) { my @words=split(/ /,$input[$currentline - 1]); #@words=reverse(@words); $input[$currentline - 1]=join(" ",@words,"\n"); } @input=reverse(@input); print(@input);

UPDATE: polished your code a little bit. Please, take a look at the in-line comments provided ;).

UPDATE 1: Ooops, accidentally pasted a line of code I used to test my way of 'thinking' (with the 'perl -e' command):
while(<STDIN>){chomp;last if m/done/i;push @a, $_;}print@a;
Sorry about that, Anonymous Monk! ;)

_____________________
$"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/; $_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print" +- $1"}&&`rm $1`; print$\;}

Replies are listed 'Best First'.
Re: Re: Ending user input
by Anonymous Monk on May 28, 2002 at 17:24 UTC
    thanks for info. I tried your script and got an error message with "@a". What does the explicit package name refer to in this error message?
    Global symbol "@a" requires explicit package name at C:\Perl\bin\EnRev +er.pl line 3.
      Hi.

      You need to precede the '@a' array with 'my'.
      You could define it above the main code section or as needed:
      my @a = qw( 1 2 3 );


      -Katie.