On 8/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi,
> 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.
>
> Let me know.
>
> Regards,
> Ninad.
use a for loop:
#!/usr/bin/perl
use strict;
use warnings;
my @line;
push @line, scalar <> for 1 .. 4;
print "the first line was\n$line[0]",
"the second line was\n$line[1]",
"the third line was\n$line[2]",
"the fourth line was\n$line[3]";
Or use a while loop with a counter variable
#!/usr/bin/perl
use strict;
use warnings;
my @line;
my $i;
while (<>) {
push @line, $_;
last if ++$i == 4;
}
print "the first line was\n$line[0]",
"the second line was\n$line[1]",
"the third line was\n$line[2]",
"the fourth line was\n$line[3]";
Or use a while loop exiting when the user types exit
#!/usr/bin/perl
use strict;
use warnings;
my @line;
while (<>) {
last if /^exit$/;
push @line, $_;
}
for my $i (1 .. @line) {
print "line $i was\n$line[$i-1]";
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/