[lug] Perl - How to pass by Reference?

Bill Thoen bthoen at gisnet.com
Wed Mar 1 17:27:56 MST 2006


On Wed, Mar 01, 2006 at 04:56:51PM -0700, Siegfried Heintze wrote:
> This is a great exercise that is not covered well in any of the tutorials I
> read when I was trying to learn perl. I found this lesson very painful.

Yes... I'm afraid I'm trying to do something in a non-Perl way. I'm having
even more trouble with the Perl book I'm using. It must be way out of date
because it doesn't even mention things like my(), much less give me
anything useful about referencing/dereferencing passed parameters. 

> First: Why are you trying to pass by reference? 

So I can have the subroutine return a boolean value while also being able
to change more than one parameter as well.

> Beware: things get more complex when passing arrays as function arguments.

I was afraid of that. In my example, I thought I'd keep it simple, but in
reality I'm passing a couple of scalers that shouldn't be altered and
(blast it) two arrays that may or may not be cleared by the subroutine
depending on the situation.

I got some help already about using \$test and $$test, and I just found
some info in 'perldoc perlsub' that might be useful. I think the O'Reilly
book I've got is going to do more to confuse me than help, since it says 
very little about this subject (not to mention that it's 15 years old
now....) 

Perhaps I need to rethink how I want to do this in light of Perl's strange
and wyrd ways. It looks just enough like C in places to trip me up. 

I think I know why its mascot is a camel, now too. They're great beasts for
taking you through hostile terrain, but they're cranky, made out of spare
parts from other animals, smell like a bathroom carpet, and if you vex them
(which doesn't take much) they'll spit in your eye. They're a pain in the
butt (literally) to ride too.

- Bill Thoen




More information about the LUG mailing list