Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Dereferencing and comment from Camelby pg (Canon) |
on Dec 21, 2002 at 05:26 UTC ( [id://221574]=note: print w/replies, xml ) | Need Help?? |
You are 80% right, but it means more than $, you should also include @, %, &. That is actually sort of comment for a person who is familiar with c/c++. In c/c++, there is a single de-ref operator *. It doesn't matter what the pointer points to, you can always use * to de-ref it. However in Perl, we do not have such a single operator for de-ref. We have to use @, %, &. There is a big difference. In Perl, in order to de-ref a ref, you have to first know what the ref refs to. In c/c++, type doesn't matter at all, you can always cast a pointer to a certain type, which may have nothing to do with the original type, and then de-ref it, as long as don't corrupt the memory boundary. (In real life, you almost always deref a pointer to something meaningful in the context) In Perl, if you do: It gives you an error, and says that $a is not a SCALAR ref. You have to do: In c/c++, * also de-ref's pointers to functions, in Perl, we have to use &:
In Section
Seekers of Perl Wisdom
|
|