Stupid Perl Humor|
I was filling out the credit card receipt at a restaurant last night. Writing in the tip and total amounts (which, by the way, I added up incorrectly. I wasn't paying too much attention), I wrote in a dollar sign. After filling it in, I noticed that the receipt had preprinted dollar signs. So I had two dollar signs.
"I'm dereferencing a scalar," I said.
Hoo boy, I crack me up.
Do you wanna translate for those of us who are a little slow? :)
Or will that make it lose its funniness?
|Date:||May 14th, 2003 11:13 am (UTC)|| |
Trust me, you really don't want to know.
But I'll tell you anyway.
A scalar is a type of variable. You prefix it with a dollar sign ($xyz). This separates it from lists (@somelist) and hashes (%somehash), different types of variables.
A reference to a variable is stored in a scalar. A reference is a pointer, the address of the actual variable. It's a lot easier to pass around a reference than it is to, say, pass around a list of 2000 numbers. So, the variable (scalar, list, or hash) is one place, and the reference gives its address.
When you get a reference and want to follow the address to the actual variable, you dereference it. To do that, you put the appropriate symbol in front of the reference. So, to dereference a list reference, you would do @$somelistreference. Same idea with a hash (%$somehashreference). Remember, the scalar $somelistreference in this case is a number that refers to an address in memory where the actual list is. Putting a @ in front of it means "follow this address, and treat whatever I find there as a list."
So, you can also have refernces to scalars. So if you have a scalar reference in $somescalarreference, to dereference it, you would put the symbol for a scalar in front of it, which is a dollar sign. So dereferencing it would be $$somescalarreference.
So, two dollar signs (with a variable name after it) means you are dereferencing a scalar.
You were right. I guess I didn't want to know. But in all sincerity, even though I didn't understand a word you said after "A scalar is a type of variable.", I really did appreciate you explaining it to me in a way that assumed I had the capacity to understand it. :) And, ultimately, I am glad that you made yourself giggle at the restaurant. :D
You know, I think they have sound medical methods to help restore a normal sense of humor for you. You should seek out a physician.
I was amused too. 8) I didn't (and don't, even) think you were weird or that you had an abnormal sense of humour.