Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Modify a hash via its reference

by bradcathey (Prior)
on Jan 23, 2008 at 12:54 UTC ( [id://663781]=note: print w/replies, xml ) Need Help??


in reply to Modify a hash via its reference

Agree with the above, but as a sidebar a couple of notes on coding style that might help readability (none critical, just some things I've picked up bashing around the Monastery):

  • No need for the "&" in front of your subroutine calls, or the space just preceding the opening parens. Include the empty set of parens if not passing a value.
  • No need for the "#" on the blank lines (visual noise)
  • No need for the "()" around a single my variable declaration</code>
  • Might want to consider an alternative to spelling out your hash values with the 'corresponds to' arrow =>
  • And personally, I like my variable and subroutine names in all lowercase (I save the title case for my module names.

So,

my %fruits = ( "Apples" => 3, "Oranges" => 6 ); print_hash(();

A great book: Perl: Best Practices.

Good luck!

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Replies are listed 'Best First'.
Re^2: Modify a hash via its reference
by Errto (Vicar) on Jan 23, 2008 at 22:51 UTC
    No need for the "()" around a single my variable declaration
    This is true in most situations but not all. From the OP's code:
    my ( $Ref_to_Hash ) = @_;
    In this style of parameter initialization, the parentheses are in fact required. Otherwise $Ref_to_Hash will be assigned the number of arguments, not the value of the first one.

      I stand corrected (which is why I love this place). Thanks, I learned something.

      —Brad
      "The important work of moving the world forward does not wait to be done by perfect men." George Eliot

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://663781]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-19 11:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found