Perl: the Markov chain saw PerlMonks

### Re^2: how to sort this?

by sen (Hermit)
 on Mar 25, 2006 at 05:57 UTC ( #539148=note: print w/replies, xml ) Need Help??

in reply to Re: how to sort this?
in thread how to sort this?

hi saint,

my requirement is to sort by integers. also i need the output as

```@a = (1x1 1x1 1x2 1x12 2x1 4x0 4x1 4x12 10x1 12x1 12x3 22x3);

Thanks

Replies are listed 'Best First'.
Re^3: how to sort this?
by gube (Parson) on Mar 25, 2006 at 10:01 UTC

Hi sen try this it gives your exact output,

```#!/usr/local/bin/perl

@a1 = qw/1x1 1x12 12x3 10x1 4x12 4x1 1x1 22x3 2x1 4x0 12x1 1x2/;
@out = sort {
(split 'x', \$a, 2)[0] <=>
(split 'x', \$b, 2)[0]
}
sort {
(split 'x', \$a, 2)[1] <=>
(split 'x', \$b, 2)[1]
}@a1;

print "@out";

Create A New User
Node Status?
node history
Node Type: note [id://539148]
help
Chatterbox?
 [LanX]: Thx found a solution! :) [Eily]: I wrote "your" instead of "you're" :'( [Eily]: I guess it means that my English is good enough that I make the same mistakes as native speakers though :/ [LanX]: your native tounge is French .... or Quebequois? [erix]: never mind the natives [Eily]: French, why? [LanX]: lately you were talking about kids confused with "la liason" [LanX]: I stopped worrying about my pronounciation and orthography "problems" in English [Eily]: ah yes, you asked about the value of neuros :)

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2017-03-27 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should Pluto Get Its Planethood Back?

Results (320 votes). Check out past polls.