in reply to Simple array sorting
Not what you thought, huh? Now, if i wanted to create an array that contained every second letter of the alphabet, i would try something like this:$VAR1 = [ undef, ${\$VAR1->[0]}, 'e', ${\$VAR1->[0]}, 'i', ${\$VAR1->[0]}, 'm', 't' ];
Next, delete all elements but the second, fourth, and sixth:my $i = 1; my @bar = grep $i++ % 2, ('a'..'z');
You could combine the two steps:@bar = @bar[2,4,6];
Finally, push 't' and "@bar" will evaluate to "e i m t". If we could just swap the 't' and the 'e' ...my $i = 1; my @bar = (grep $i++ % 2, ('a'..'z'))[2,4,6];
Is this what you wanted? Note that this line by itself will not yield the same results if you simply try to cut and paste into your script. Here is my complete script, for convenience:($bar[0],$bar[-1]) = ($bar[-1],$bar[0]);
use strict; use warnings; my $i = 1; my @bar = (grep $i++ % 2, ('a'..'z'))[2,4,6]; push(@bar,'t'); ($bar[0],$bar[-1]) = ($bar[-1],$bar[0]); print "@bar\n";
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Simple array sorting
by Hofmator (Curate) on Jan 09, 2003 at 08:19 UTC |