Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re-ordering data branches in a [Tree::DAG_Node] tree

by tybalt89 (Monsignor)
on Apr 23, 2018 at 02:14 UTC ( [id://1213400]=note: print w/replies, xml ) Need Help??


in reply to Re-ordering data branches in a [Tree::DAG_Node] tree

Fun little problem :)

#!/usr/bin/perl # http://perlmonks.org/?node_id=1213391 use strict; use warnings; my @test_data = ( 'a', # ' b', # ' e', # ' f', # ' g', # ' c', # ' d', # 'h', # ' i', # ' j', # ); my $onestring = join '', map "$_\n", @test_data; print $onestring, "=" x 60, "\n"; print group($onestring); sub group { my @groups; push @groups, "$1" . group("$3") while $_[0] =~ /(( *).*\n)((?:\2 +. +*\n)*)/g; join '', sort @groups; }

Replies are listed 'Best First'.
Re^2: Re-ordering data branches in a [Tree::DAG_Node] tree
by AnomalousMonk (Archbishop) on Apr 23, 2018 at 04:44 UTC

    Why not just

    c:\@Work\Perl\monks>perl -wMstrict -le "my @test_data = ( 'a', ' b', ' e', ' f', ' g', ' c', ' d', 'h', ' i', ' j', ); print for @test_data; print '==========='; ;; print $_->[0] for sort { $a->[1] cmp $b->[1] } map [ $_, m{ \w+ }xmsg ], @test_data ; " a b e f g c d h i j =========== a b c d e f g h i j


    Give a man a fish:  <%-{-{-{-<

      Because it fails for

      my @test_data = ( 'j', # ' i', # ' h', # ' g', # ' f', # ' e', # ' d', # 'c', # ' b', # ' a', # );

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-18 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found