Dixon"
<[EMAIL PROTECTED] To: [EMAIL PROTECTED]
am.co.uk>cc:
Subject: Re:
"Steven Massey" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
m...
>
> If you could explain how this works, especially how $a $b are set with
the
> compare values
>
> my @sorted = sort {
> (split ':', $a)[-1] <=> (split ':', $b)[-1]
> } @array;
The block is evaluated for
CTED] To: [EMAIL PROTECTED]
am.co.uk>cc:
Subject: Re: sorting thoughts
On Wed, 29 Jan 2003 16:50:03 +, Steven Massey wrote:
> I have an array, each line contains fields seperated by ":"
> I want to sort the array numerically ascending by the last field.
>
> my thoughts are to split fields into seperate arrays, go through the last
> array in a comparing process,
Bob Showalter wrote:
>
> This will be quicker than the other methods, especially as the array size
> grows. Try your benchmark with an array of say 10, or 100 elements.
>
yes, it's faster. i didn't include the code since this algr. is well known.
just some number for those who are interested:
B
david wrote:
> Steven Massey wrote:
>
> >
> > I have an array, each line contains fields seperated by ":"
> > I want to sort the array numerically ascending by the last field.
> >
> > my thoughts are to split fields into seperate arrays, go through
> > the last array in a comparing process, mov
Steven Massey wrote:
>
> I have an array, each line contains fields seperated by ":"
> I want to sort the array numerically ascending by the last field.
>
> my thoughts are to split fields into seperate arrays, go through the last
> array in a comparing process, moving each row index in the orig
"Steven Massey" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
m...
> Hi
>
> just about to embark on a sorting routine, and I thought before I
spend
> ages(at my ability) I would see what thoughts you guys have on this.
>
> I have an array, each line contains fields seperated by ":"
From: [EMAIL PROTECTED]
> just about to embark on a sorting routine, and I thought before I
> spend ages(at my ability) I would see what thoughts you guys have on
> this.
As Slobodan Jaksic correctly pointed out a few weeks ago I don't have
any thoughts of my own. I just point people to docs :-P
[EMAIL PROTECTED] wrote:
> Hi
>
> just about to embark on a sorting routine, and I thought before I
> spend ages(at my ability) I would see what thoughts you guys have on
> this.
>
> I have an array, each line contains fields seperated by ":"
> I want to sort the array numerically ascending by
Undoubtedly not the best way of doing this, but here's one stab at it.
This assumes you have your data stored in an array as a single string,
rather than having an array of array pointers.
my @array = ('fred:lucy:24', 'john:jane:10', 'frank:mary:5');
@array = sort { my @a_vals = split (':', $a);
11 matches
Mail list logo