Good day,

  This would be quick and simple. I need to write a
script that will prompt the user(using <STDIN>) to
enter a series of numbers separated by white space and
then push each of those numbers into an array and then
do anything such as sorting it from highest to lowest.

I've tried doing it as:

print "Enter your numbers separated by space: ";
my @array = <STDIN>;
print sort @array;

..nothing happened after pressing return.

Then I've tried putting the <STDIN> to a scalar first
before assigning it to an array.

my $numbers = <STDIN>;
my @array = $numbers;
print $array[-1];  #(print the last element)

Then it only printed exactly what I've entered as if
it has treated the numbers as a single string.


I'm thinking perhaps if only I could place the
contents of <STDIN> inside a qw() and assign it to an
array like this;

@array = qw(23 43 2 5 1);

then I would have no problem with spaces between
them(and eventually I can do anything with each of its
elements). Only that I don't know how to get it in
place starting from user input <STDIN>.

Any idea?

Thanks.














                
__________________________________ 
Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 
http://mobile.yahoo.com/maildemo 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to