Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: Subroutine Parameters

by chargrill (Parson)
on May 31, 2007 at 04:13 UTC ( #618388=note: print w/replies, xml ) Need Help??

in reply to Re: Subroutine Parameters
in thread Subroutine Parameters

In your code snippet, the "user" sub was written to expect an array reference and a hash reference as its args, but when you called the sub, you forgot to put backslashes in front of the args, and so you passed the full list of array values and hash keys and values instead. I suspect that was a copy/paste error when you posted the code. If it had been that way in the script that you actually ran, I think you would have gotten an error message (something about "can't treat a string (or number?) as an array reference")

Not quite - prototypes silently coerce arguments to match prototypes in this case. In perlsub:

Any backslashed prototype character represents an actual argument th +at absolutely must start with that character. The value passed as part + of @_ will be a reference to the actual argument given in the subroutin +e call, obtained by applying "\" to that argument.

Grandfather was actually explaining about the return assignment:

my (@age_r, %home_r) = user(@age,%home);

s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://618388]
[choroba]: I configured signature font to 2pt size, so I don't care
[choroba]: Moreover, I don't find the Big Lebowski quote offensive
Lady_Aleena wishes she could format her signature a bit without getting metaphorical hives.

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2017-06-23 09:15 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (539 votes). Check out past polls.