STDIN-perl

Good morning!

How do I make the info that someone inputs from @userArray = <STDIN>, a new array?

@userArray = <STDIN>;
while ()
{
        chomp;
        last if ! /\d/;
        push(@userArray,$_);
}
my($sum,$avg) = &sumIt(@userArray);
print "Total:$sum\nAverage:$avg\n";

Im trying to capture what the user is inputing in the <STDIN>.

Any help would be greatly appreciated!

Ben

Not sure what exactly you are looking for, but does this help ?

$
$
$ perl -lne 'push @x, $_;
             END {print "The input array is as follows:"; foreach (@x){print}
                  print "Sum     = ", eval(join("+",@x));
                  print "Average = ", eval(join("+",@x))/($#x+1);
                 }'
10
20
30
40
^Z
The input array is as follows:
10
20
30
40
Sum     = 100
Average = 25
$
$

The numbers in blue are input by the user at the command-line.
The text in red is a "Control+Z" and then the "Return" key, and it is an indication to the Perl program that the input has been terminated.
The text in green is printed by the Perl program.

tyler_durden

Perfect!! Ok to switch it up and learn...

what is I wanted to divide the user input by 2?? THis is my code below...

I know /2 means divide by 2 correct?

[code]
print "The input array divided by 2 is as follows:\n"; foreach (@userArray)/2 {print}
my($sum,$avg) = &sumIt(@userArray);
print "Total:$sum\nAverage:$avg\n";

[code1]

thanks
ben