Log in

No account? Create an account
May 14th, 2003
12:36 pm


Previous Entry Share Next Entry
Stupid Perl Humor

(5 comments | Leave a comment)

Date:May 14th, 2003 09:48 am (UTC)
Do you wanna translate for those of us who are a little slow? :)

Or will that make it lose its funniness?
[User Picture]
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.
Date:May 14th, 2003 12:01 pm (UTC)

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
My Website Powered by LiveJournal.com