Neat problem! I like Corion's answer, but here is another way to try out. The idea is to split each entry on the slash to create an array. Then you eval that array into a hash data structure:
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;
This produces a data structure like so:
$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:
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;
But this does not work correctly:
$VAR1 = [ 'Location/', 'Topology/IPClassA/Device/log_ratio/' ];
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?'

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)

In reply to (jeffa) Re: Unique Array Entries by jeffa
in thread Unique Array Entries by The_Rev

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.