Rather than describing a solution that you can't find, how about describing the problem you are trying to solve. Not the little piece you are having trouble with, but the whole thing.

You seem to be scanning files and extracting some information from them, but you only give us a portion of a single file as sample data and don't show us enough to demonstrate the problem you are having.

You may find it helps to create a stand alone script to demonstrate the problem. The following starting point may help:

use strict; use warnings; use Data::Dump::Streamer; my %files; $files{wibble} = <<'END_FILE'; Name=foo Icon=bar Categories=a;b;c END_FILE $files{floop} = <<'END_FILE'; Name=baz Icon=boo Categories=x;y;z END_FILE my %collection; for my $file (keys %files) { open my $inFile, '<', \$files{$file} or die "Can't open $file: $!" +; my %collect; while (my $line = <$inFile>){ chomp $file; my ($var, $value) = split '=', $line, 2; $collect{$var} = $value if defined $value; } $collect{categories} ||= "Misc"; $collect{icon} ||= "-"; $collection{$file} = \%collect; } Dump \%collection;

Prints:

$HASH1 = { floop => { Categories => "x;y;z\n", categories => 'Misc', Icon => "boo\n", icon => '-', Name => "baz\n" }, wibble => { Categories => "a;b;c\n", categories => 'Misc', Icon => "bar\n", icon => '-', Name => "foo\n" } };

True laziness is hard work

In reply to Re: Building an arbitrary-depth, multi-level hash by GrandFather
in thread Building an arbitrary-depth, multi-level hash by Anonymous Monk

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.