How would I go about writing a Perl Progam that can take user entered lines from the keyboard and then store them in an array?
Whenever the user enters "QUIT" the program will print out all of the lines sorted. THen you must change the program so that it will tell you how many lines have entered and then print out only lines 2, 3, and 4.

At least post what you have ok?

some code will you ;)

I think that I am supposed to use this and here is my example:
$userinput=<>;
chomp ($userinput);
print"$userinput\n";

I guess then I type in a line? I am new to this perl programming and confused.

Edited 6 Years Ago by Anthony Cameron: n/a

Thats easy.

You must have a file to write append your entered data.

Once you quit, You read the size, print 2,3,4lines from the file.

That is any entered input by the user is stored append to the file.

Simple ;)

Thats easy.

You must have a file to write append your entered data.

Once you quit, You read the size, print 2,3,4lines from the file.

That is any entered input by the user is stored append to the file.

Simple ;)

So basically, I have to have a txt file with data. I should have a script that opens and reads the file and closes it. Then I should print the 2nd, 3rd, and 4th line from the txt file?

Just format your lines well that is \n will do. and you can count your lines by reading one line after the other with increment operator.

If you are happy, you leave a comment ;)

You can also store them in an array as you wanted.

using

print "enter your name\n";
$takeIn=<>;
chomp $takeIn;
@d=$takeIn

## use shift on the array to add the additional data user enters.

Then iterate the array to get the all the user entered info.

Thats also simple ;)

Edited 6 Years Ago by richieking: n/a

I wonder Why would you want to use

$takeIn=<>;
chomp $takeIn;
@d=$takeIn

instead of:

@d=<>;
chomp @d;

Edited 6 Years Ago by sysadm1n: n/a

I wonder Why would you want to use

$takeIn=<>;
chomp $takeIn;
@d=$takeIn

instead of:

@d=<>;
chomp @d;

Thank you for the help

This article has been dead for over six months. Start a new discussion instead.