in reply to Incrementing a hash of array value
Produces...#!/bin/perl5 use strict; use warnings; my %hash=(); %hash=( "M01.001" => 0, "M01.001.111" => 0, "M01.001.111.111" => 0, "M01.002" => 0, "M01.002.003" => 0 ); my %HoA; for my $k ( keys %hash ){ $k =~ /(M\d{2}\.\d{3})/; my $parent = $1; push @{$HoA{$parent}}, $k } foreach my $parent ( sort keys %HoA ) { print "$parent\n"; foreach my $i ( 0 .. $#{$HoA{$parent}} ) { my $child = $HoA{$parent}[$i]; next if $parent eq $child; print "\t$child\n"; } print "\n"; }
How complex is the hierarchy? Would any 'children' have 'children' too?M01.001 M01.001.111 M01.001.111.111 M01.002 M01.002.003
The second loop came from perldsc. I think what you need is in there somewhere.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Incrementing a hash of array value
by Raad (Acolyte) on Jul 26, 2004 at 13:35 UTC | |
by wfsp (Abbot) on Jul 26, 2004 at 14:40 UTC |