Update! got working code that reads csv file and creates hash table. Surprisingly, when i print and check hash size, script displays 13 and prints 13 keys and 13 values. I should have minimum 150 keys/values in hash table. Does anyone take a look and suggest any workarounds!!!
Column_1,Column_2 Name11,In Name21,Out Name31,In Name41,In
use Data::Dumper; my $infile = file.csv; sub mainCSV { open (my $infile1, '<', "$infile") or die "Unable to open $infile: + $!"; my %hash = (); while (my $line = <$infile1>) { chomp; $line =~ s/\s*\z//; my @array = split /,/, $line; my $key = shift @array; $hash{$key} = \@array; } my $size = scalar keys %hash; # explicit scalar context print "Hash size: $size\n"; # prints Hash size: xx print Dumper(\%hash); }
In reply to Re^4: csv to hash table
by waytoperl
in thread csv to hash table
by waytoperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |