Could someone please give me an idea what this hash structure would look like, and how I would go about getting the last index number of the first set of array numbers. (Something like $#{$db{'key1'}{'key2'}} maybe?) And also, how would I go about deleting the array? I don't want to do delete $db{'key1'}{'key2'}, but something more along the lines of delete $db{'key1'}{'key2'}[3].
@{$db{'key1'}{'key2'}[0][0]} = "one_value"; @{$db{'key1'}{'key2'}[0][1]} = "two_value"; @{$db{'key1'}{'key2'}[1][0]} = "three_value"; @{$db{'key1'}{'key2'}[1][1]} = "four_value"; @{$db{'key1'}{'key2'}[2][0]} = "three_value"; @{$db{'key1'}{'key2'}[2][1]} = "four_value"; print "how many elements does the array have : ", scalar (@{$db{'key1'}{'key2'}}); print "\n"; print "popping an element"; pop @{$db{'key1'}{'key2'}}; print "\n"; print "how many elements does the array have now : ", scalar (@{$db{'key1'}{'key2'}});
now, if you want to do this in the middle of an array, you'll want to splice instead of pop. Some people may argue that popping isn't exactly the correct behavior here, since it's being called in a void context, so you might want to capture it, if need be.
In reply to Re: Array in a Hash (boo);
by boo_radley
in thread Array in a Hash
by mt2k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |