Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Passing variables into a subroutine

by AnomalousMonk (Canon)
on Sep 03, 2012 at 22:47 UTC ( #991519=note: print w/replies, xml ) Need Help??


in reply to Passing variables into a subroutine

The other alternative, if you don't want to deal with references and if there is only one array (or hash) to be passed, is to pass any and all scalars (and there can be more than one) first, and then pass the sole array (or hash). The following works the same way with or without the  (@) prototype for the reason explained by CountZero (i.e., in general, don't bother with prototypes):

perl -wMstrict -le "sub S { my ($scalar, @ra) = @_; ;; print qq{scalar: '$scalar' array:(@ra)}; } ;; my @array = (1, 2, 3); S('foo', @array); " scalar: 'foo' array:(1 2 3)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991519]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2017-01-19 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (170 votes). Check out past polls.