LPM: passing array refs

Rich Bowen rbowen at rcbowen.com
Fri Jan 21 19:41:41 CST 2000


Matt Cashner wrote:
> 
> is there any way to pass an array ref transparently? ie
> 
> foo(@array,$var);
> 
> but by prototyping or something :) @array is actually passed in as a ref?

There's a good article on prototypes at
http://www.perl.com/pub/language/misc/fmproto.html
I don't use them much myself, having never been a C programmer, so I
can't say much about how they work. Except that, if you are a C
programmer, they don't work the way that you expect them to.

It does seem that they do what you want them to do. Sort of.
See
http://www.perl.com/pub/language/misc/fmproto.html#Reference_Prototypes

If you give your subroutine a prototpe of \@$, for example, and pass in
an array and a scalar, it magically converts the array to an array ref
on the way to the function. This is not exactly what you asked for, but
sort of half way. 

The problem, of course, is that if you have a prototype of @$, how would
perl know when the array was to stop and the scalar to start? So you end
up with all your arguments in the array, and nothing in the scalary.
Worse yet, imagine @$@, and try to figure out what goes in the scalar if
I pass (1,2,3,4,5,6,7).

Anyways, prototypes are sort of handy, but I've never actually used them
myself, because I don't see that they simplify anything for me.

Rich
-- 
http://www.ApacheUnleashed.com/
Lexington Perl Mongers - http://lexington.pm.org/
PGP Key - http://www.rcbowen.com/pgp.txt



More information about the Lexington-pm mailing list