Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Dereferencing and comment from Camel

by pg (Canon)
on Dec 21, 2002 at 05:26 UTC ( #221574=note: print w/replies, xml ) Need Help??

in reply to Dereferencing and comment from Camel

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:
%a = (1,1,2,2); $a = \%a; print $$a;
It gives you an error, and says that $a is not a SCALAR ref. You have to do:
%a = (1,1,2,2); $a = \%a; print %{$a};
In c/c++, * also de-ref's pointers to functions, in Perl, we have to use &:
sub a { print "abc"; } $a = \&a; &{$a}; # call a, and prints abc

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://221574]
[Discipulus]: i cannot see any link to tye post..
[Lady_Aleena]: Hello.
[marto]: teleconf + coffee, I'll post it in a few mins
[beech]: fencepost?
beech is protected with velcro
[Lady_Aleena]: How is velco protective? It sticks to a lot of things.

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2017-06-23 08:55 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (539 votes). Check out past polls.