#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; use Data::Diver qw/ DiveVal /; open my $fh, '<', \q{Ho|001 -> ooB -> Ho.62 Ho|001 -> nom -> rapidqa Ho|001|VAG|001 -> VAG -> 21.00.00.E0.8B.80.7E.7D Ho|001|VAG|002 -> VAG -> 21.00.00.E0.8B.80.E7.7F Ho|001|BigUnit|001 -> ooB -> LU.R700.87108.8234 Ho|001|BigUnit|001 -> deR -> 8234 Ho|001|BigUnit|002 -> ooB -> LU.R700.87108.8235 Ho|001|BigUnit|002 -> deR -> 8235 Ho|002 -> ooB -> Ho.107 Ho|002 -> nom -> sapfvir03 Ho|002|VAG|001 -> VAG -> 21.00.00.E0.8B.81.D7.F6 Ho|002|VAG|002 -> VAG -> 21.00.00.E0.8B.81.4C.F9 Ho|002|BigUnit|001 -> ooB -> LU.R700.87108.10336 Ho|002|BigUnit|001 -> deR -> 10336 }; my $root = {}; while(<$fh>){ s/\s+$//; my( $left, $mid, $right ) = split ' -> ', $_; my @paths = map { \$_ } split(/\|/, $left), $mid; DiveVal( $root, @paths ) = $right; } dd $root; __END__ { Ho => { "001" => { BigUnit => { "001" => { deR => 8234, ooB => "LU.R700.87108.8 +234" }, "002" => { deR => 8235, ooB => "LU.R700.87108.8 +235" }, }, nom => "rapidqa", ooB => "Ho.62", VAG => { "001" => { VAG => "21.00.00.E0.8B.80.7E.7D" }, "002" => { VAG => "21.00.00.E0.8B.80.E7.7F" }, }, }, "002" => { BigUnit => { "001" => { deR => 10336, ooB => "LU. +R700.87108.10336" } }, nom => "sapfvir03", ooB => "Ho.107", VAG => { "001" => { VAG => "21.00.00.E0.8B.81.D7.F6" }, "002" => { VAG => "21.00.00.E0.8B.81.4C.F9" }, }, }, }, }

In reply to Re^2: hash magic (hash from path) by Anonymous Monk
in thread hash magic by hrmnbth

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.