http://qs1969.pair.com?node_id=405724

sulfericacid has asked for the wisdom of the Perl Monks concerning the following question:

Something I've heard and seen are people using anonymous hashes and arrays and because up to this point I never came across a reason to use them, this is all new to me.

I read a few tutorials online, LP3 doesn't seem to mention it and the Perl Cookbook has a small section on it I've read but I have a few questions.

Is an anonymous hash also known as a multi-dimensional hash where you can literally have different hashes inside of a single hash?

The problem I am trying to get through is creating a mess of hashes on the fly and add records to them without having to create 150 or so different hash names.

An example of what I am trying to do would be a set of hashes for each meta tag (see below). This would be for EACH meta tag. Now in the real world, I don't want to manually create a hash for each possible meta tag.

Meta tag name Meta tag value Meta tag character count Meta tag word count Meta tag word repeat count
Real example:
Title Welcome to my website! 22 4 1 Keywords candy, food, pop, candy cane, soda, caffeine 31 5 2
This isn't what I'm really trying to do with it but this seemed to be the best way to explain what I am trying to do. I have hundreds of separate hashes I need to create dynamically and store values into and someone mentioned anonymous hashes and arrays are the way to go.

An example from http://search.cpan.org/~nwclark/perl-5.8.5/pod/perlref.pod:

$hashref = { 'Adam' => 'Eve', 'Clyde' => 'Bonnie', };
This doesn't look like anything more than single key/value pairs and I don't see examples on how to do what this script requires.

How practical are anonymous hashes and arrays? This is the first time I've ever had to do them and it's because I need dynamic hashes created without needing to create new hashes. Is the primary use for these to create arrays or hashes dynamically?

Thanks for your help wise monks.



"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid