Though I doubt the overhead will have a significant impact, even with really large hashes, using each is indeed more optimized.
That, and another optimization I thought of after posting my code, would change the subroutine to:
sub DigThroughHashref {
my $hr_data = shift;
while (my ($key, $value) = each %{$hr_data}) {
if (ref ($value) eq "HASH") {
print ("Digging through [$key]:\n");
DigThroughHashref($value, @_, $key);
} else {
print (join ('->', @_) . "->$key - $value\n");
}
} ## end while (my ($key, $value) ...
} ## end sub DigThroughHashref
All occurrances of $_ are now replaced by $key, and all occurrances of $hr_data->{$_} are now replaced by $value.
Also, the seperate variable @keystack is now optimized out. Instead of pushing the to-be-parsed key explicitly onto the end of @keystack, it is now simply added to the arguments of the sub (which results in it being added to @_ inside the sub).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.