CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Sorting

 



thsuk1
New User

Sep 2, 2010, 11:24 AM

Post #1 of 2 (1228 views)
Sorting Can't Post

I would like to sort the array in reverse order, but it did not work


Code
@arr = (474, 445, 453); 
@arr = sort { $a < $b } @arr;
foreach my $aa (@arr){
print "$aa, ";
}


I expected the result of this code would be '474, 453, 445', but it printed '474, 445, 453'.

What is a problem? How can I solve it?

Thanks.


shawnhcorey
Enthusiast


Sep 2, 2010, 11:28 AM

Post #2 of 2 (1226 views)
Re: [thsuk1] Sorting [In reply to] Can't Post


Code
@arr = sort { $b <=> $a } @arr;


See `perldoc -f sort`

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives