Don't ask to ask, just ask | |
PerlMonks |
Re: Small troubles with referencesby wfsp (Abbot) |
on Feb 09, 2006 at 20:12 UTC ( [id://529179]=note: print w/replies, xml ) | Need Help?? |
Hi coldmiser! I agree with you, references can be tricky beasties to get the hang of. You successfully passed refs to your sub and de-referenced them. That's half the battle won already! But you can, in fact, pass an array or a hash to a sub. Change your test script to test it. The problem arises when, say, you want to pass two arrays. Perl will 'flatten' both arrays into one array and copy it into @a1. @a2 will be empty. If you pass refs: $a1ref and $a2ref now contain the refs you passed and you can use them as you did in your snippet. You might also write a script that changes the array/hash passed into a sub and then look at what they look like after the sub has been called. Your snippet also raises the question of scoping (as duff mentions). Have a look at Coping with Scoping to get more of an idea of what going on. You're nearly there, good luck!
In Section
Seekers of Perl Wisdom
|
|