Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Passing variables into a subroutine

by AnomalousMonk (Monsignor)
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)


Comment on Re: Passing variables into a subroutine
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-08-30 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls