Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Creating a Multi Level Hash from CSV

by 1nickt (Abbot)
on May 13, 2021 at 11:16 UTC ( #11132531=note: print w/replies, xml ) Need Help??


in reply to Creating a Multi Level Hash from CSV

Hi,

Important to note that there are repeated values, which is the case for the provided sample output, (ie info 01 = info11, info02 = info12, etc.), but this is not always the case.

Although your sample data does not correspond with this comment, you should consider that hashes have unique keys.

use strict; use warnings; use feature 'say'; use Data::Dumper; my %hash; while (<DATA>) { chomp; my @items = split ','; $hash{ $items[0] } = $items[1]; } say Dumper \%hash; __DATA__ a,b a,c x,y
Output:
$ perl 11132513.pl $VAR1 = { 'a' => 'c', 'x' => 'y' };

Hope this helps!


The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11132531]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2021-10-22 01:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?