in reply to Generation of a Hash of Hashes
Note that before your iron down what you want your representation to be, you should try to write sample code to do the tasks that you need to do using this representation. I'm trying to figure out for what task this data structure would be convenient, and I'm having no luck. Combined with your inexperience, I'd take this as a sign that you probably need a different representation but don't know what.#!/usr/bin/perl -w use strict; use Data::Dumper; my %result; for my $l (<DATA>) { my ($cod,$desc) = ($l =~/(\d*) (.*)/); my $hashref = \%result; my $partial = ''; foreach my $layer (split //, $cod) { $partial .= $layer; $hashref = ($hashref->{$partial} ||= {}); } $hashref->{0} = $desc; } print Dumper \%result; __DATA__ 1 ITEM 11 Sub Item 1 111 Item X 112 Item 1121 Another Item 11212 And Another Item 12 Sub Item 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Generation of a Hash of Hashes
by Miguel (Friar) on Mar 25, 2005 at 23:08 UTC | |
by tilly (Archbishop) on Mar 26, 2005 at 01:22 UTC |