Creating arrays and hashes in perl

→ Are you a new visitor? Please visit the page guidance for new visitors ←

Creating arrays and hashes in perl

I’m sure for those users looking for dynamically storing their information they will most likely rely at some point on arrays. Here are some quick snippets on how to create arrays and associative arrays in perl (hashes).

Creating an array in perl

Arrays are preceded by the symbol “@”, these are standard arrays used for simple loops of data. For example:

This is a really simple usage of an array.

Creating an associative array in perl (hashes)

These are actually called hashes (“%”) in perldocs, but for me its easier to call them associative arrays because are really similar to this. The usage is slightly different than normal arrays in perl, see below:

It is clearly similar to associative arrays, correct?

Creative hashes of hashes in perl

Now here’s the really big stuff, when going even more advance, you would use multi level arrays, this is usually used with hashes, see below:

The same for arrays of arrays, its really that simple. You can then create a multi level array or hashes or array of array or hashes of hashes, from there you really have a lot of freedom.

Request an article ←