Perl

Moderators: Jonathan
Number of threads: 1211
Number of posts: 3568

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
sort array and return index Posted by JamesR416 on 25 Aug 2010 at 12:26 PM
hello all, i'm trying to do something simple, but i was hoping there might be an easy and efficient way to do it. i'm currently using sort to find the max value in an array:

my $max = (sort {$b <=> $a} @y)[0];

but i'm wondering if there is a way to get sort (or some other built in function) to return the original index of this value. right now i have a naive for loop doing the job, and i need to speed it up and was hoping to avoid writing a more efficient search routine myself.

thanks,
JR



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.