The array2 is the array that will hold the numbers. Now, do I need to loop through the STDIN to get 5 numbers? DO I need to enclose the STDIN in the loop? I'd appreciate some advice, I wouldn't want the code because I would like to try to do it myself thanks

you are taking it the wrong way, if I understand what you want correctly.

in:

Code

my @array = qw|first second third fourth|;

you are giving values to the first fourth elements of your array. It is unlikely that is what you are rally trying to do. (BTW, "first" will be the value of $array[O], "second the value of $array[1], and so on. This is also presumably not what you want.

Now, you have basically two ways of handling your problem.

You can loop through the array, and, for each element of this array, ask your user what she or he wants for a value. Or you want your user to enter a string aith all the value, for example something like "17, 13, 7, 9876, 1" (or possibly "17 13 7 9876 1", or whatever) and then assign each number with proper code to do it.

Both approaches are feasible and quite easy. It is up to you to decide on how vou want to do it. Obviously, the coding will be different depending on how you expect your user to enter the data.

Hello BillKSmith , thanks for your code but I am at the very beginning of my perl leanrning experience, so there are quite a few things I am not too sure I understand in your code. Would you be able to give me a hand with that please? Before doing that, I think my code was a bit confusing. The first array

Code

@array

isn't really part of what I was trying to achieve (save the values input by the user in an array) it is just an array I created holding 4 values, that's all : - ) 1)join method. I had a look at it also online, but I am not sure I understand exactly what it does.

, what does it do? What do the angle brackets signify? The split function usualy is used to convert a string to an array..but how about this?

Code

my @array2 = split /\s/, $response;

here

Code

if (@array2 != 5) {

are we saying if the array hasn't 5 numbers?

hope you can help me thanks.

@Laurent_R As said above the first array doesn't have anything to do with what I was trying to achieve, sorry for the confusion. So back to the econd array array2 which is the one that will contain the numbers input by the users. DO you mean something like this?

Prompt the user to enter five numbers. Store his answer in the scalar $response.

Code

my @array2 = split /\s/, $response;

Parse his response by splitting it on whitespace. Store each number in an element of @array2.

Code

if (@array2 != 5) { die "Invalid input\n"; }

If the user did not follow instructions and enter exactly five numbers, his input is invalid. Abort with a message that tells him so. (In production code, we would also verify that all his fields are in fact numbers.)

Code

print "\n"; foreach (@array2) { print; print "\n"; }

Print the input data, one number per line. (I probably should have used join for this array also.) Good Luck, Bill