Brian L. Matthews explains it here as follows:
- A reference is not a memory address. If you go to the memory address corresponding to the scalar value of a reference you will not find your data there.
- A reference contains type information. A mere memory address, on the other hand, contains no type information and thus can store any object.
- Larry Wall intentionally decided to use the term "reference" rather than "pointer" so that people would understand that Perl is not pointing to a memory address.
As Larry points out, Perl is not appropriate for all applications. For example, Perl itself is not written in Perl, it is written in C. If you have an application which requires low-level manipulation of the contents of memory addresses then that application is not an appropriate candidate for coding in Perl.
Furthermore, it says in the Learning Perl book by our own Merlyn et al that a reference is somewhat like a pointer, but it is safer. Presumably one reason that a reference is safer is that one cannot easily manipulate references to poke holes that can be exploited in an operating system.
| [reply] |
Thanks. I guss I will use somethin else to do this.
| [reply] |
Let's say I know the exact location of a peice of data
Let's say...you don't. :) I tell you what, you tell me how
you know this, and I'll tell you how to do it. You won't like
the answer.
For starters, you can't take a string and get a viable reference
from it. Well, almost. It involves XS programming and that's
torture for most people.
What'cha got in memory? How do you know it's there? Is this
part of your process or someone else's? Is this a machine API (BIOS?)?
Inquiring minds want to know.
| [reply] |
Perl is definitely the wrong language to play around with
this kind of thing. OTOH if you want to proceed, there
are two ways to go.
The first is to install Inline and proceed from
there. The second is to use unpack with "P" to get at
what is in a particular spot in the memory of your current
process. You should not be able to get at the memory of
other processes this way.
If you are on a *nix system and have root access you can
play around with /dev/mem to find what memory looks like.
Of course if you wanted a good seed for random numbers,
you are better off either trusting Perl to do a good job,
or using something like Math::Random. | [reply] |
I doubt this is possible (besides which, how do you know where this data is in memory? Will it always be in that same place?), and even if it were, I'd hate to maintain any code that used this sort of technique.
Perhaps if you told us what you were trying to accomplish we could come up with a better (and indeed, more Perlish) way to do it...
| [reply] |
Why I wan this? First of all curiosity. Second of all, playing with memory addresses is fun ;) Also a result of looking at the contents of a random address is the perfect seed. It would be very interesting to directly controll the mempry. | [reply] |