Input from stdin for perl

I'm trying to take input from STDIN and push them in to an array.  I want the input to end when the user hits enter, but I can't seem to get it working correctly.  Here is what I've tried so far:

my @numbers;

while (<>) {
    s/\s+\z//;
    last if $_ eq "";
    push @numbers, $_;
}

I seem to get a blank array, any ideas?
bmcquillAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
What was the input from STDIN, and what made the array seem blank?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bmcquillAuthor Commented:
THe input was just 1,2,3,4,5
And I got back 0 when I tried to print the contents of the array.
0
ozoCommented:
How did you try to print the contents?
Was 1,2,3,4,5 all on one line?  Were there any lines before the 1,2,3,4,5?
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

bmcquillAuthor Commented:
No lines before 1,2,3,4,5, entered all on one line.

I tried to print the array by print "@numbers\n" and print "$numbers\n" both.
0
ozoCommented:
echo "1,2,3,4,5" | perl -e '
my @numbers;

while (<>) {
    s/\s+\z//;
    last if $_ eq "";
    push @numbers, $_;
}
print "@numbers\n"
'

Open in new window

works for me, printing
1,2,3,4,5
as one array elwment
0
FishMongerCommented:
Is this what you're looking for?
echo "1,2,3,4,5" | perl -e '
my @numbers;
while (<>) {
    push @numbers, split /\D+/;
}
print "$_\n" for @numbers
'

Open in new window

Ountputs:
1
2
3
4
5
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.