Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Do you know where your variables are?
 
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 drinking their drinks and smoking their pipes about the Monastery: (11)
As of 2014-04-17 19:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (454 votes), past polls