We don't bite newbies here... much | |
PerlMonks |
Re: Pointers and Referencesby kcott (Archbishop) |
on Nov 23, 2020 at 04:40 UTC ( [id://11124049]=note: print w/replies, xml ) | Need Help?? |
G'day Leudwinus, "I am still trying to wrap my head around ..." You're using terms — pointer, address, memory location — which I suspect you've picked up from one or more other languages. You are then attempting to apply those terms to Perl, assuming they have the same meaning. I think this may be the source of your problems. I'd suggest the first thing to do would be to look at perlintro; in particular, the "Perl variable types" section. At the end of that section you'll find the gentlest of introductions to references with a list of other links to more information; I'd suggest checking out perlreftut first. Consider the following:
You can reference and dereference to great depths if you want; as in this exaggerated example:
The construct \(...), where ... is some list, evaluates to a list of references to each element of the list:
You can take references to other data types:
and dereference them:
You can take references to references:
and dereference them one level at a time:
I suggest you play around with examples like these to get a better understanding of how all of this works. Also note that I didn't use, or indeed need, terms such as pointer, address or memory location. You used strict and warnings in your OP which is very good. I suggest you do the same with oneliners. Here's a common alias I use; you might want to set up something similar for yourself (although, perhaps, one a little less involved).
That will pick up things like this:
— Ken
In Section
Seekers of Perl Wisdom
|
|