On 2012-01-18 04:31, Chris Stinemetz wrote:
Would someone kindly advise me in sorting this array:
my @array = qw(c r v vr tr re c.p[1] c.p[3] c.p[2] c.p[4] c.p[7]
c.p[6] c.p[5] c.p[8] c.t[1] c.t[3] c.t[2]);
I only want to sort the elements that have a numeric value inside the
braces so that all the other elements have their original index
preserved.
Sample output I am trying to accomplish:
c
r
v
vr
tr
re
c.p[1]
c.p[2]
c.p[3]
c.p[4]
c.p[5]
c.p[6]
c.p[7]
c.p[8]
c.t[1]
c.t[2]
c.t[3]
perl -wle '
my @array = qw(c r v vr tr re c.p[1] c.p[3] c.p[2] c.p[4]
c.p[7] c.p[6] c.p[5] c.p[8] c.t[1] c.t[3] c.t[2] );
print for ( grep !/\[/, @array),
(sort grep /\[/, @array);
'
c
r
v
vr
tr
re
c.p[1]
c.p[2]
c.p[3]
c.p[4]
c.p[5]
c.p[6]
c.p[7]
c.p[8]
c.t[1]
c.t[2]
c.t[3]
Though that would sort c.t[10] in front of c.t[2].
--
Ruud
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/