every time user input create array perl

Hi, How to create array every time user input and store user input and display all array

print " Enter input "
my @input  = split(' ', $input)
chmop($input = <STDIN>;
foreach ($input)
{
 @array= @input;
}
print @array"\n";

A couple of points,

  1. use strict; and use warnings; when you are learning, they reduce time spent debugging (when you know everything and never make typos feel free to stop using them)
  2. Do you want to have the array items separated by newlines, or by spaces on a single line?
  3. Your code looks as though it was copied over the shoulder of someone who has an array of tokens extracted from a line - why is that?
  4. You have to have values in a string before you can split it.
  5. The foreach structure in your code makes no sense at all, syntactically foreach takes a list not a scalar, you then make a crazy assignment within the loop.

Try and code up something like the following and get back to us if you hit an issue

  • call the interpreter
  • apply the strict and warnings pragmas
  • print your request
  • read from standard input (and chomp inline if you wish)
  • split the values in the input into an array
  • print your array (I like to use print join(', ', @input_tokens),"\n"; when printing an array as it looks nicer)

Hope that helps, by the way check your spelling as well :slight_smile:

perldoc -f chomp