Perl Dynamically Generated Multidimentional Associative Array -



Perl Dynamically Generated Multidimentional Associative Array -

this may simple oversight on part (or much more advanced skill set). trying dynamically fill 2d associative array reading input file.

my @data; while (<file>) { chomp; $id,$count; print "read: " . $_ . "\n"; #debug 1 ($id,$count,undef,undef,undef) = split /\,/; print "data: " . $id . "," . $count . "\n"; # debug 2 $data{$id}{"count"} = $count; #push @{$data{$id}{"count"}}, $count; print $data{$id}{"count"} . "\n"; # debug 3 }

the first print (debug 1) print line similar des313,3,,,.

the sec print (debug 2) print line data: des313,3

the 3rd print (debug 3) print blank line.

the issue seems in way trying insert info associative array. have tried both direct insert , force method no results. have done php think overlooking in perl. did @ perldoc perldsc page in section of hashes of hashes did not see talk dynamic generation of them. suggestions great!

assigning hash way have should work fine. declaring variables improperly. associative array called hash in perl, , prefixed % sigil, should write my %data before while loop. within loop, my operator needs parens apply list, should my ($id, $count);.

this minimal illustration works properly:

use warnings; # place these lines @ top of of programs utilize strict; # grab many errors %data; # hash variable while (<data>) { chomp; ($id, $count) = split /,/; # simplify split $data{$id}{count} = $count; # build hash } print "got: $data{des313}{count}\n"; # prints "got: 3" __data__ des313,3

perl multidimensional-array associative-array

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -