Here is my perl program followed by my output.
What am I missing? Thanks so much for any help
Write a Perl program that reads a list of strings and then a number (all on separate lines), and then prints one of the lines from the list as selected by the number.
Here’s what it should look like when you run this program:
% program.pl
Enter some text: This is the first line
Enter some text: This is the second line
Enter some text:
Enter a number: 2
The text in line 2 is: “This is the second line”
%
This is my code:
C:\Perl\bin>per l program.pl
Enter some text: This is the first line
Enter some text: This is the second line
Enter some text:
Enter a number: 2
The text in line 2 is:
What am I missing? Thanks so much for any help
Write a Perl program that reads a list of strings and then a number (all on separate lines), and then prints one of the lines from the list as selected by the number.
Here’s what it should look like when you run this program:
% program.pl
Enter some text: This is the first line
Enter some text: This is the second line
Enter some text:
Enter a number: 2
The text in line 2 is: “This is the second line”
%
This is my code:
Code:
#! perl -w
$inc = 0;
while ($inc < 4) {
if($inc < 3){
print 'Enter some text: ';
chomp($input = <STDIN>);
@array = $input;
}else{
print 'Enter a number: ';
chomp($input = <STDIN>);
}
$inc++;
}
printf("The text in line $input is: @array");
Enter some text: This is the first line
Enter some text: This is the second line
Enter some text:
Enter a number: 2
The text in line 2 is:
Comment