I like using plain hashes unless necessary. The same goes with arrays, and subroutines. References are extremely useful tools, but using them for everything seems a bit silly.

What are my reasons? Well, one might be overhead. There is a small amount of overhead involved in dereferencing, though to be honest this doesn't concern me that much.

A much more important reason is tidiness. All those arrows do not take long to type, and they don't really make it extremely difficult to read, but they do add some noise. Frankly, I think we should take advantage of any decrease we can get, in terms of visual noise. Consider the following examples:

@{$href}{"one", "two", "three"}; # hash slice, hashref @hash {"one", "two", "three"}; # hash slice, hash for (0 .. $#{$aref}) {} # index iteration, arrayref for (0 .. $#array) {} # index iteration, array # with references @{$aref2} = map { $href1->{$_} + 1 } sort { $href2->{$a} <=> $href2->{$b} } grep /foo/, @{$aref1}[0 .. $#{$aref1}/2]; # without @array2 = map { $hash1{$_} + 1 } sort { $hash2{$a} <=> $hash2{$b} } grep /foo/, @array1[0 .. $#array1/2];

Sure, the versions using references aren't terribly much more difficult to follow than the ones without. It's not that big of a difference, but like I've said before, every little bit helps. This kind of thing adds up quickly to create a mess.


In reply to Re^4: Dynamic variables by revdiablo
in thread Dynamic variables by xspikx

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.