in reply to trees of word lists
I'm not sure what you might consider obscure so the following non-recursive code might be either obscure or elegant:
use strict; use warnings; use Data::Dump::Streamer; my @list1 = qw/Truck Car Byke/; my @list2 = qw/Truck Car Scooter/; my @list3 = qw/Truck Trailer Skates/; my %tree; for my $list (\@list1, \@list2, \@list3, ) { my $node = \%tree; $node = $node->{shift @$list} ||= {} while @$list; } Dump \%tree;
Prints:
$HASH1 = { Truck => { Car => { Byke => {}, Scooter => {} }, Trailer => { Skates => {} } } };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: trees of word lists
by lostjimmy (Chaplain) on Jan 22, 2009 at 20:18 UTC | |
by MidLifeXis (Monsignor) on Jan 23, 2009 at 19:39 UTC |