Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
If you don't feel like using the Tree module, you can build your data structure by temporarily storing the references to each hash in a separate hash, as follows.
use strict; use Data::Dumper; my %data; { my %temp; while (<DATA>) { chomp; /^(.*?):(.*?)$/; my $key = $2; my $value = $1; if (!defined $temp{$key}) { $temp{$key} = {}; $data{$key} = \%{$temp{$key}}; }; $temp{$key}{$value} = \%{$temp{$value}}; }; } print Dumper \%data; __DATA__ b:a c:a d:b e:c f:c
This code generates the following dump of %data:
$VAR1 = { 'a' => { 'c' => { 'e' => {}, 'f' => {} }, 'b' => { 'd' => {} } } };

I'm not sure what you mean by I have no idea how to store this either. . If your looking for a way to save and load data to disk, you can use Data::Dumper and 'do' as follows.
use strict; use Data::Dumper; my %saved = ( 'test1' => { 'test2' => 'b' }, 'b' => [1,2,3,4], 'test3' => 'x' ); print "Constructed hash\n"; print Dumper \%saved; open FILE, ">save.out"; print FILE Dumper \%saved; close FILE; my %loaded = %{do 'save.out'}; print "Loaded hash\n"; print Dumper \%loaded;
Be aware though that saving and loading hashes this way can be a security risk if your script and saved file have different read/write permissions for different users. (i.e. If security is set up in such a way that a user is unable to edit the Perl script, but is able to edit save.out, this would introduce a way for that user to execute code in the Perl script.)

In reply to Re: how to construct tree from parent pointer list by Anonymous Monk
in thread how to construct tree from parent pointer list by bfdi533

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (5)
    As of 2020-11-27 00:39 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found