in reply to Re: Re: using map to generate a hash of hash
in thread using map to generate a hash of hash

Is each one of these records on a line by itself?
If so, then you want either to read the input line by line, or split the content on newlines first.

And then you probably want to use split rather than a regex, to parse each record.

Example:

my %hash = map { my( $a, @b ) = split /\|/; defined $a ? ( $a => { @b } ) : () } split /\n+/, $content;
Also, I wonder what the subhashes are supposed to look like. Do you have a fixed set of keys, and only the values come from the input records? In that case, you could have something like this:
my @subhash_keys = qw( something another ); my %hash = map { my( $a, @b ) = split /\|/; my %b; @b{ @subhash_keys } = @b; defined $a ? ( $a => \%b ) : () } split /\n+/, $content;
Of course, ultimately, you may find it more convenient to use a more traditional for loop. It would also be more efficient for large input files.