in reply to Re: array of hash
in thread array of hash
perhaps I didn't fully understand your comment but i changed my program based on use strict. I still have problem
If I don't use the hash ref, I get this error Can't use string ("CD") as a HASH ref while "strict refs" in use at ./test.pl line 15.
and if i use hash ref, I don't get any value for the key CD Don't know why?! curr CD AB 1 currhash CD AB 1
The desired output is curr CD 0 AB 1 currhash CD 0 AB 0
#!/usr/bin/perl use strict; sub parseFiles{ my @currArr=(); my %curr; my %tmp = $_[0]; push @currArr,'+1'; push @currArr,'u'; push @currArr,%tmp; # push @currArr,%currHash; in the first case $curr{"my"}=[@currArr]; $curr{"my"}->[2]{"AB"}++; #print scalar(keys %{$curr{"my"}->[2]}), "\n"; #print $curr{"my"}->[0], " ", $curr{"my"}->[1], "\n"; print "curr\n"; foreach (keys %{$curr{"my"}->[2]}){ print $_, " ", $curr{"my"}->[2]{$_}, " "; } print "\n"; print "currhash\n"; foreach (keys %tmp){ print $_, " ", $tmp{$_}, " "; } print "\n"; } sub storeHash{ my %currHash; $currHash{"AB"}=$currHash{"CD"}= 0; return %currHash; } sub main{ my %currHash; %currHash=storeHash(); parseFiles(%currHash); } main();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: array of hash
by choroba (Cardinal) on May 27, 2014 at 11:00 UTC | |
by carolw (Sexton) on May 27, 2014 at 11:18 UTC | |
by choroba (Cardinal) on May 27, 2014 at 11:26 UTC | |
by carolw (Sexton) on May 27, 2014 at 11:45 UTC | |
by choroba (Cardinal) on May 27, 2014 at 12:28 UTC | |
by carolw (Sexton) on May 27, 2014 at 12:37 UTC | |
by choroba (Cardinal) on May 27, 2014 at 12:42 UTC | |
by carolw (Sexton) on May 27, 2014 at 12:31 UTC | |
by carolw (Sexton) on May 27, 2014 at 12:51 UTC |