Your skill will accomplishwhat the force of many cannot PerlMonks

### Re^3: sort array by date

by BrowserUk (Pope)
 on Jan 04, 2007 at 14:43 UTC ( #592954=note: print w/replies, xml ) Need Help??

``` print for sort qw[ 12 a123 a122 A123 B123 Ab123 aB123 456 1A23 1a23 ]
+;;
12          ## ord('1') == 49, ord('2') == 50
...
a122
a123
aB123
```
```print for sort{ \$b cmp \$a } qw[ 1 10 100 2 20 21 3 300 ];;
300
...
100
10
1
```
```print for sort{ \$b <=> \$a } qw[ 1 10 100 2 20 21 3 300 ];
300
...
3
2
1
```
```print for sort{
substr( \$a, 1 ) <=> substr( \$b, 1 )
...
D222
A473
B659
```
```## Build an array of anonymous arrays,
## each of which contains the sort field and the original element.
...
print Dumper \@sorted;;

\$VAR1 = ['E001','C123','D222','A473','B659'];
```
```@sorted = map{
\$_->[1]
...

print Dumper @sorted;;
VAR1 = 'E001'; \$VAR2 = 'C123'; \$VAR3 = 'D222'; \$VAR4 = 'A473'; \$VAR5 =
+ 'B659';
```
```print for map{
\$_->[2]
...
A473
B659
C659
```
```print for map{
## Chop off the bit we added.
...
D222
A473
B659
```
```print for map{
unpack 'x[N] A*', \$_
...
D222
A473
B659
```
```print for map{
unpack 'x[NA1]A*', \$_
...
A473
B659
C659
```

Create A New User
Node Status?
node history
Node Type: note [id://592954]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2018-04-26 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My travels bear the most uncanny semblance to ...

Results (94 votes). Check out past polls.

Notices?