Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: how to construct tree from parent pointer list

by nothingmuch (Priest)
on Mar 22, 2006 at 09:54 UTC ( #538455=note: print w/replies, xml ) Need Help??

in reply to how to construct tree from parent pointer list

Anonymous Monk's code can be slightly beautified:
use strict; use Data::Dumper; my %deep; { my %flat; while (<DATA>) { chomp; my ( $child, $parent ) = /^(.*?):(.*?)$/; # if the parent is new then it's possibly at the root of the struc +ture # like 'a' is unless ( exists $flat{$parent} ) { $flat{parent} = $deep{parent} = {}; } # find the parent, and mark this node as a child of it $flat{$parent}{$child} = ($flat{child} ||= {}) # since $child is a child of $parent it can't be at the root, so d +elete it if it's there delete $deep{$child}; }; }
zz zZ Z Z #!perl

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://538455]
[LanX]: DBI: is there an easy method to get the content of a column as an array
[LanX]: values %{ $DBI->fetchrow_has href('column_name' }
[LanX]: ehm ... fetchall_hashref
[Jenda]: my int @a = ^5_000_000 Coerces the argument to Numeric, and generates a range from 0 up to (but excluding) the argument.
[Jenda]: The apparent design principle of Perl6 operators was "Let's confuse 'em dudes." Whose braindead idea was this particular operator and the three hundred around it?

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2018-07-16 16:52 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (344 votes). Check out past polls.