I’m sending a subroutine a hash, and fetching it with my($arg_ref) = @_;
But what exactly is %$arg_ref? Is %$ dereferencing the hash?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
$arg_refis a scalar since it uses the$sigil. Presumably, it holds a hash reference. So yes,%$arg_refdeferences that hash reference. Another way to write it is%{$arg_ref}. This makes the intent of the code a bit more clear, though more verbose.To quote from
perldata(1):So your example would be:
my($arg_ref) = @_;grabs the first item in the function’s argument stack and places it in a local variable called$arg_ref. The caller is responsible for passing a hash reference. A more canonical way to write that is:To create a hash reference you could start with a hash:
Or you can create it with an anonymous hash reference: