in reply to Creating a Multi Level Hash from CSV
Something like this? I faked an input file because you did not include a valid input file.
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11132513 use warnings; my %hash; while( <DATA> ) { my ( $top, @rest ) = split /,|\n/; # FIXME faking CSV for testing $hash{$top} = chain(@rest); } use Data::Dump 'dd'; dd \%hash; sub chain { return @_ > 1 ? { shift() => chain(@_) } : shift(); } __DATA__ a,b,c,d,e f,g,h,i,j xx,yy,zz this,is,a,strange,type,of,data,organization
Outputs:
{ a => { b => { c => { d => "e" } } }, f => { g => { h => { i => "j" } } }, this => { is => { a => { strange => { type => { of => { data => "organizatio +n" } } } }, }, }, xx => { yy => "zz" }, }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Creating a Multi Level Hash from CSV
by Fletch (Bishop) on May 14, 2021 at 12:43 UTC | |
|
Re^2: Creating a Multi Level Hash from CSV
by workInProgress12 (Novice) on May 13, 2021 at 17:18 UTC | |
by AnomalousMonk (Archbishop) on May 13, 2021 at 20:02 UTC | |
|