On 05/14/2014 12:31 AM, Mike Dunaway wrote:
What's a good use of references? When is it ideal to use them? Why would
you want to use them?



I learned C before I learned perl. I think understanding it in C will also help: http://how-to.linuxcareer.com/c-development-on-linux-pointers-and-arrays-vi

You could just also google "C pointer tutorial"

For the most part, if you are passing multiple variables into a function and one is an array, you will more than likely want to pass the array as a reference. This is because an array passed into a function will get expanded into list context. So if you pass an integer and a 3 element array into a function, within the function it will look like you passed 4 variables.

Also another common use is with hashes too. Perhaps you want an array and each element is info from a customer account. You could make a hash with the keys being "customer_name", "account_id", "city", and then you can push a reference to that onto an array. Later on in your program, you can pop each element off the array and work on it (or just iterate through it)

If you are a beginner, I can recommend picking up the "Beginning Perl" book by Curtis Poe :)

--Sam

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to