in reply to Unique Array Entries
This produces a data structure like so:use strict; use Data::Dumper; $Data::Dumper::Indent = 1; my %thingy; my @lines = ... # insert your data here for (sort @lines) { my ($type,$stuff) = $_ =~ /([A-Z]):\s+(.*)/; my @parts = split('/',$stuff); push @parts,''; my $str = q|$thingy{'| . shift(@parts) . q|'}|; for my $part (@parts) { $str .= qq|->{'$part'}|; } eval $str; } print Dumper \%thingy;
$VAR1 = {
'Location' => {},
'Topology' => {
'IPClassA' => {
'Device' => {
'log_ratio' => {},
'poll_interval' => {}
},
'Device = 2' => {
'Port' => {
'ifPhysAddress' => {},
'poll_interval' => {}
},
'is_managed' => {},
'poll_interval' => {}
}
},
'IPClassC' => {
'Device' => {
'poll_interval' => {}
}
}
}
};
Now all you need is some code to turn the data structure
back into a list of paths:
But this does not work correctly:my (@list,$flat); flatten($_,$thingy{$_}) foreach keys %thingy; sub flatten { my ($key,$rest) = @_; unless ($rest) { push @list,$flat; undef $flat; return; } $flat .= "$key/"; flatten(%$rest); } print Dumper \@list;
Sorry, but i am at my wit's end on this one (Saturday morning laziness :D). At this point, my 'answer' turns into a question: 'How do you recursively "flatten" this data structure?'$VAR1 = [ 'Location/', 'Topology/IPClassA/Device/log_ratio/' ];
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: Unique Array Entries
by Corion (Patriarch) on Mar 02, 2002 at 16:40 UTC | |
by The_Rev (Acolyte) on Mar 02, 2002 at 16:48 UTC | |
by Corion (Patriarch) on Mar 02, 2002 at 16:58 UTC | |
by The_Rev (Acolyte) on Mar 02, 2002 at 16:56 UTC | |
by The_Rev (Acolyte) on Mar 02, 2002 at 16:59 UTC |