freelanceprogrammers.org Forum Index » Perl

New to Perl


View user's profile Post To page top
perl_1978 Posted: Fri May 07, 2004 11:38 pm


Joined: 07 May 2004

Posts: 7
New to Perl
I`m trying to sort some numerical values in ascending order from some
output that I print to screen. Would anyone know how to do this?

Steve
Reply with quote
Send private message
View user's profile Post To page top
perl_jam03 Posted: Sat May 08, 2004 6:27 am


Joined: 05 May 2004

Posts: 16
New to Perl
I guess you mean "from some input source before I use it as output that
I print to screen", right?

Look into getting you numbers into an array variable like @numbers, and
then sorting them with

@sorted = sort { $a <=> $b } @numbers;

`sort` by itself sorts alphabetically, so `35` would be before `7`, so
that is why you need to include the block. Read the documentation on
`sort` (perldoc -f sort) for greater insight into the function and how
to use it in this fashion.

Rex


--- perl_1978 <no_reply@yahoogroups.com> wrote:
> I`m trying to sort some numerical values in ascending order from some
>
> output that I print to screen. Would anyone know how to do this?
>
> Steve
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
Reply with quote
Send private message
View user's profile Post To page top
xrraj Posted: Sat May 08, 2004 9:08 am


Joined: 08 May 2004

Posts: 1
New to Perl
Use sort function.

raymond raj

--- In perl_official@yahoogroups.com, perl_1978 <no_reply@y...> wrote:
> I`m trying to sort some numerical values in ascending order from
some
> output that I print to screen. Would anyone know how to do this?
>
> Steve
Reply with quote
Send private message
View user's profile Post To page top
perl_1978 Posted: Sat May 08, 2004 11:25 pm


Joined: 07 May 2004

Posts: 7
New to Perl
This sounds familar. I will check the docs and see what it says
about the sort function. Thanks


--- In perl_official@yahoogroups.com, El Rex <rex@b...> wrote:
>
> I guess you mean "from some input source before I use it as output
that
> I print to screen", right?
>
> Look into getting you numbers into an array variable like
@numbers, and
> then sorting them with
>
> @sorted = sort { $a <=> $b } @numbers;
>
> `sort` by itself sorts alphabetically, so `35` would be
before `7`, so
> that is why you need to include the block. Read the documentation
on
> `sort` (perldoc -f sort) for greater insight into the function and
how
> to use it in this fashion.
>
> Rex
>
>
> --- perl_1978 <no_reply@yahoogroups.com> wrote:
> > I`m trying to sort some numerical values in ascending order from
some
> >
> > output that I print to screen. Would anyone know how to do this?
> >
> > Steve
> >
> >
> >
> >
> >
> > Yahoo! Groups Links
> >
> >
> >
> >
> >
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help