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" } };
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |