in reply to Re: Re: using map to generate a hash of hash
in thread using map to generate a hash of hash
And then you probably want to use split rather than a regex, to parse each record.
Example:
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 %hash = map { my( $a, @b ) = split /\|/; 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.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;
|
|---|