Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Structures defaulting to flat lists!

@Arrays and %Hashes act per default as list not as reference which makes many useful things complicated and only some other things easy.

For instance @a=(@b,@c) is not a nested structure but a flattend list, so you better choose $a=[$b,$c].

So if your working with nested structures or your passing structure in and out subroutines you need to switch to references, where you need much more typing, and you loose the "documenting" advantage of sigils.

Especially if you return large arrays out of a sub as a ref to avoid copying, you cant alias them to a normal @array you need a $arr_ref.

e.g. this doesn't work:

my (*arr)= ret_arr_ref(); print @arr

Even if you decide as a consequence to constantly work with references and you enjoy dereferencing with the arrow-operator it's annoying that you can't use the special commands for arrays and hashes directly. You need to put extra dereferencing and often additionally enclosing curlies:

 push @{ $hash_ref->{key_to_arr} }, "elem"

instead of

 push $hash_ref->{key_to_arr}, "elem"

Personally I think this is the biggest obstacle for beginners, a complication where many decide to look for a more intuitive language (in this aspect)!

Cheers Rolf

In reply to Re: disadvantages of perl by LanX
in thread disadvantages of perl by perldesire

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (2)
    As of 2018-05-27 20:36 GMT
    Find Nodes?
      Voting Booth?