in reply to Re: Sort this data
in thread Sort this data
because then @hashrefs would be in reverse!" Yes, that's absolutely right. And it might be inefficient to reverse() the array when we're done with it, and it's also inefficient to keep unshift()ing to the array. So what possible efficient solution could I come up with to combine the splice() speed with the insertion speed?while (my ($a,$b,$c) = splice(@data, -3)) { push @hashrefs, { a => $a, b => $b, c => $c }; pop @data; # null field }
What a sneaky trick I've done.my @hashrefs; $#hashrefs = int(@data / 4); my $i = $#hashrefs; while (@data and my ($a,$b,$c) = splice(@data, -3)) { $hashrefs[$i--] = { a => $a, b => $b, c => $c }; pop @data; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re (tilly) 3: Sort this data
by tilly (Archbishop) on Nov 19, 2000 at 20:42 UTC | |
|
(jcwren) Re: (3) Sort this data
by jcwren (Prior) on Nov 19, 2000 at 19:55 UTC | |
by japhy (Canon) on Nov 19, 2000 at 20:04 UTC | |
|
Re: Re: Re: Sort this data
by extremely (Priest) on Nov 20, 2000 at 01:47 UTC | |
by japhy (Canon) on Nov 20, 2000 at 01:52 UTC |