This will help, amoung other things, track down typos. In tester() you have $HoHMarer where you almost certainly mean $HoHMarker. Nail down those sort of errors and you are often halfway there.my $popCt = 1; my $markers = 2;
I find it easier to track down bugs by supplying a sub all the arguments it needs so that it is a self contained script on its own. This means you can test it on its own, it doesn't rely on anything that might be happening a hundred lines further up or further down the script. This way you can test your script with sample known good/bad data and check that it behaves as expected.
Again in tester(), the first three lines are
What do you expect $newcounter to be? undef would not be a lot of use here. Strict would force you to declare it and you may need it to be an argument that you pass to the sub.sub tester { my @holder = @{$HoH{$newcounter}{'holder'}}; my @ind = @{$HoH{$newcounter}{'individual'}}; my %HoHMarker = %{$HoH{$newcounter}{'marker'}};
Pass your subs all the args it needs. If it needs a lot construct a hash/hashref.my $newcounter = 1; tester($newcounter); #... sub tester { my ($newcounter) = @_; ... }
You could also debate how useful %HOH is as a name, something more meaningful (but short) might make the code easier to read.my $args = { arg1 => $arg1, arg2 => $arg2, arg3 => $arg3, }; tester($args); ... sub tester{ my ($args) = @_; ... }
Some more error checking wouldn't go amiss and Data::Dumper is, as you have, a very useful tool. When I'm trying to get some sense out of a script I use the ... or die "somevar is $somevar"; liberally, and when things are really bad on everyother line. :-)
As an example, in tester() again
Have all your subs return a value. Even if it is only true on success and false on failure. The "return early, return often" idiom can make your subs logic a lot easier too. It would also assist testing/error checking.sub tester { my @holder = @{$HoH{$newcounter}{'holder'}}; die "tester: holder is empty" unless @holder;
Finally,my $success = tester(); die "tester failed" unless $success;
...is there a way to have an array name itself...With strict and warnings on the answer is "no". Self modifying code is considered a bad idea but there are many alternatives, a hash lookup being popular.
Try to write a script that demonstrates the snag you're having trouble with (not the whole lot!) and we'll see where we go from there.my %user_data_lookup; ... my $safe_input = validate($user_input); push @{$user_data_lookup{$safe_input}}, @some_array; ...
Good luck! Let us know how you get on.
In reply to Re: HwithinHoA? Complex Data Structure...I am so lost...
by wfsp
in thread HwithinHoA? Complex Data Structure...I am so lost...
by BioNrd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |