Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Passing variables into a subroutine

by AnomalousMonk (Archbishop)
on Sep 03, 2012 at 22:47 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://991519]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-20 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found