if process() returns the hash refarence, shouldn't it return the refarence to $data (the hash refarence {as an update}) ?

The process() sub is altering a global hash, so everything else in the script has access to the updated hash data simply by using the same global. The fact that process() is returning a reference to that hash is irrelevant, because you never actually use the return value anyway.

Using a subroutine to alter global data this way can often make the code harder to understand and harder to maintain. It also makes it easier to create bugs that are hard to track down, because any subroutine could create unintended side effects by altering globals when you didn't really intend to do that.

For scripts of limited complexity (like yours, if it were written sensibly), using globals could make things seem simpler overall, and that's fine; but if you ever decide to re-use this or that subroutine from the script, the presence of globals inside the subs will make this harder than it should be.


In reply to Re^3: Hash confusion ?! by graff
in thread Hash confusion ?! by thenetfreaker

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.