Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://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

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?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 13:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found