Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Sorting path like strings

by Aristotle (Chancellor)
on Jan 05, 2006 at 14:42 UTC ( [id://521217]=note: print w/replies, xml ) Need Help??


in reply to Sorting path like strings

I’d use a GRT variant.

use List::Util qw( max ); my @padded = do { my @copy = @path; my @segment_length; while( 1 ) { my $len = max map { s!([^/]*/|[^/]+)!! ? length( $1 ) : -1 } @ +copy; last if $len == -1; push @segment_length, $len; } my $format = join '', map "%${_}s", @segment_length; map {; no warnings 'uninitialized'; sprintf $format, split m!/!, $_, -1; } @path; }; @path = @path[ sort { $padded[ $a ] cmp $padded[ $b ] } 0 .. $#padded +];

Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://521217]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (1)
As of 2024-04-25 03:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found