G'day atcroft,
Here's a method using non-destructive transliteration. It requires 5.14 (see perl5140delta: Non-destructive substitution). The guts of the solution is:
sort { $a =~ y/ //dr cmp $b =~ y/ //dr } @data
I've tested with your OP data and tybalt's offering:
#!/usr/bin/env perl use 5.014; use warnings; my @test_data = ( [ atcroft => [ 'a', # ' b', # ' e', # ' f', # ' g', # ' c', # ' d', # 'h', # ' i', # ' j', # ]], [ tybalt => [ 'j', # ' i', # ' h', # ' g', # ' f', # ' e', # ' d', # 'c', # ' b', # ' a', # ]], ); say_sorted(@$_) for @test_data; sub say_sorted { my ($who, $data) = @_; say "Data from $who"; say '-' x 20; say for @$data; say '-' x 20; say for sort { $a =~ y/ //dr cmp $b =~ y/ //dr } @$data; say '=' x 20; }
Output:
Data from atcroft -------------------- a b e f g c d h i j -------------------- a b c d e f g h i j ==================== Data from tybalt -------------------- j i h g f e d c b a -------------------- a b c d e f g h i j ====================
— Ken
In reply to Re: Re-ordering data branches in a [Tree::DAG_Node] tree
by kcott
in thread Re-ordering data branches in a [Tree::DAG_Node] tree
by atcroft
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |