On Aug 21, 1:13 pm, [EMAIL PROTECTED] (Chas Owens) wrote:
> On 8/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > I am trying to take Multi Line Input in PERL.
> > But unable to do that, pls let me know, how can i do that?
>
> > for eg;
> > I wanna take 3-4 strings from users, after every string user will
> > press"enter"and the next typed letters will go into some other
> > string..
>
> > basically, i wanna take many strings from user as a input and store it
> > in an array.
> use a for loop:
>
> my @line;
> push @line, scalar <> for 1 .. 4;
> Or use a while loop with a counter variable
> my @line;
> my $i;
> while (<>) {
> push @line, $_;
> last if ++$i == 4;
> }
> Or use a while loop exiting when the user types exit
> my @line;
> while (<>) {
> last if /^exit$/;
> push @line, $_;
> }
Option 4: Read from STDIN in list context, and instruct the user to
push CTRL-D when done:
print "Enter each line, CTRL-D to end\n";
my @lines = <>;
Paul Lalli
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/