Gossamer Forum
Home : General : Perl Programming :

hash ref <-- ???

Quote Reply
hash ref <-- ???
I was going through the links admin area and came across this.

hash ref

I'm assuming that it has something to do with variables and reference but could somebody explain this in simple english. I'm not planning to change/code/hack ... I'm just interested in what it means.

Thanks and sorry for such a lame question.Blush

openoffice + gimp + sketch ... Smile
Quote Reply
Re: [QooQ] hash ref <-- ??? In reply to
A hashref is a reference to a hash.

eg...

$var = 'Hello';

$bla = \$var;

print $$bla;

So in a way you are referencing $var through $bla

The example above is not a hashref although it is a reference.

An example of a hashref would be:

%hash = ( Key1 => 'Value1' );

$hashref = \%hash;

Then in order to access the %hash keys you would do $hashref->{Key1};

Or you could do:

%$hashref = (KEY => "VALUE");

print $$hashref{KEY};

Hope that helps a bit.

Last edited by:

RedRum: Nov 4, 2001, 6:10 AM
Quote Reply
Re: [RedRum] hash ref <-- ??? In reply to
Crazy

thanks Paul. In a sense I get it but .... I think I finally got it. Long ago my programming skills stopped around this level. (brain ... grinding heavily here)

So you're saying that a hash is essentially like hash patotoes? Better yet like a salad! Where the salad represents the HASH and the keys (put in order) would represent the ingredients of the salad (lettuce, tomatoes, onions, etc ...) and ie key1 = lettuce. Is this what you're saying?

The reference part I think I understand. Reminds me of truth tables I studied eons ago!

I like to visualize things in order to understand what I'm learning or studying.

thanks!

openoffice + gimp + sketch ... Smile
Quote Reply
Re: [QooQ] hash ref <-- ??? In reply to
Actually, the "salad" (hash) contains the integredients and their associated types/values.

Example:

Code:

%salad = (Tomatoes => 'Green,Red'.
TomatoeTypes => 'Regular,Cherry',
Peppers => 'Green,Red',
PepperTypes => 'Jalapeno,Bell'
);

========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Chewbaca] hash ref <-- ??? In reply to
For tomatotypes and peppertypes you'd need [ ] if you were using individual values.

...and you wouldn't want . after Red'

Last edited by:

RedRum: Nov 4, 2001, 4:57 PM
Quote Reply
Re: hash ref <-- ??? In reply to
Smile

thanks guys, I'm not trying to code anything just trying to make more sense of the GT scripts.

So with Eliot's above example %salad would be very similar to links site_html/templates %globals ?

the salad allegory makes more sense than the actual code for me Blush

openoffice + gimp + sketch ... Smile
Quote Reply
Re: [QooQ] hash ref <-- ??? In reply to
Eliot's example is a normal hash. This would create a hashref:

$salad = \%salad;
Quote Reply
Re: [RedRum] hash ref <-- ??? In reply to
so you're saying that a hashref will take on all values of a regular hash.

openoffice + gimp + sketch ... Smile
Quote Reply
Re: [QooQ] hash ref <-- ??? In reply to
Yep.
Quote Reply
Re: [RedRum] hash ref <-- ??? In reply to
it's kind of like this... just because a variable has a '$', doesn't mean it's a scalar. you can do $foo = [] and make $foo an array, or $foo = {} and make $foo a hash. all you have to do is reference it correctly, @$foo for an array and %$foo for a hash. then accessing the elements is like $foo->[0] for an array or $foo->{bar} for a hash. bet I just confuzlled you :-)

--Philip
Links 2.0 moderator

Last edited by:

PerlFreak: Nov 5, 2001, 11:09 AM
Quote Reply
Re: [PerlFreak] hash ref <-- ??? In reply to
Was this directed at QooQ?
Quote Reply
Re: [RedRum] hash ref <-- ??? In reply to
yep. sorry... just habit to respond to the last post.

--Philip
Links 2.0 moderator
Quote Reply
Re: [PerlFreak] hash ref <-- ??? In reply to
Crazy

I'm getting this but ... I really never did like the foo/bar association ... I'm more of the real "life" exmple type of guy. KISS - Keep It Short & Stupid <-- great to use this acronym in a class room.

Thanks guys for the Perl lesson ... With the above threads I'm now able to make a little more sense out of the regular Links program.

Anybody wanna send me a copy of the CAMEL book ? Blush

openoffice + gimp + sketch ... Smile
Quote Reply
Re: [QooQ] hash ref <-- ??? In reply to
I thought it was Keep It Simple Stupid.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Chewbaca] hash ref <-- ??? In reply to
Hmm Keep It Short & Simple!
Quote Reply
Re: [RedRum] hash ref <-- ??? In reply to
Sly actually I do believe that Paul is correct but I've heard Eliot's version too. Oh well ... I guess it depends on the crowd that you're talking with!

Crazy

openoffice + gimp + sketch ... Smile
Quote Reply
Re: [QooQ] hash ref <-- ??? In reply to
English folk are polite so we don't call people "stupid" Tongue
Quote Reply
Re: [RedRum] hash ref <-- ??? In reply to
Smile

well, err ... yes ... but ....

openoffice + gimp + sketch ... Smile
Quote Reply
Re: [RedRum] hash ref <-- ??? In reply to
So that's why you tell people to RTFM ???

- wil
Quote Reply
Re: [RedRum] hash ref <-- ??? In reply to
I take it you are not a typical English then. Tongue
========================================
Buh Bye!

Cheers,
Me

Last edited by:

Chewbaca: Nov 7, 2001, 7:27 AM
Quote Reply
Re: [Wil] hash ref <-- ??? In reply to
Quote:
So that's why you tell people to RTFM ???

Ok Wil, find a post where I said RTFM
Quote Reply
Re: [RedRum] hash ref <-- ??? In reply to
It looks like Paul did not himself use RTFM, but he did respond in a Thread where it was posted:

http://www.gossamer-threads.com/...135810=View+Threaded
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Chewbaca] hash ref <-- ??? In reply to
Guess I'm not guilty as charged then....