And by the way, it's nice to do a favor for yourself within the subroutine that's receiving the reference to name the variable with a little suffix that implies that the scalar variable is not just a number or a string but that it is a REFERENCE flavor of scalar! e.g.
use strict;
my %hash = qw( abc xyz );
print "Hash key(s) are:\n";
print "$_\n" foreach my_sub( \%hash );
sub my_sub {
my ( $hash_hr ) = @_;
return ( keys %$hash_hr );
}
In this case, since passing a hash reference, my suffix is 'hr'. If it was an array reference, I'd tack on '_ar'. The suffix does nothing to guarantee that what's in that scalar variable is really an array reference or a hash reference, but it sure makes reading over the code later easier when you are trying to remember what each variable is supposed to be doing and how it is built.
By the way, even though only one argument is being passed, I like my subroutines to receive them from @_ via list context since it makes it easier to grow/evolve the subroutine later on. Same for passing return values....
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.