Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

In reply to Introduction to anonymous arrays and hashes by sulfericacid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2023-02-05 07:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (31 votes). Check out past polls.

    Notices?