Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
"Or more simply as:" I would say that is debatable.

I think that sometimes we get a bit carried away with the "zoom" of Perl and don't emphasize the basics for beginners, i.e. we would do well to consider the audience when suggesting code.

The OP is a biologist, not a SW person. The purpose of my post was to show code that only used the most basic parts of beginning Perl - something simple - both from the program logic and the syntax. Also, this code may actually run faster than some some more terse versions!

For the OP, what jwkrahn is demonstrating here is called a "hash slice". This essentially combines multiple hash assignment statements, like: $hash{a}=0; $hash{b}=1; together as one statement, could be: @hash{'a','b'}=(0,1); This is great and cool stuff, but a plain old foreach() loop is just fine. Shorter code does not necessarily run faster - in fact, sometimes it runs slower, but it is sometimes easier to write for those "in the know". Perl is loaded with idioms. Extensive use of them is not necessary to write good solid, clear, high performing code.

The syntax for a hash slice looks similar to that of an array as a hash value. @{$hash{value}}, but it is not. The HoA (Hash of Array), @{$hash{value}} is the "take home", "use it often", "get used to seeing it" message here. A hash slice is less often encountered.

Anyway, my point here is that a hash slice is probably not "easier" for a beginner to understand because of the syntax.


In reply to Re^5: making presence/absence table from a hash of arrays by Marshall
in thread making presence/absence table from a hash of arrays by reubs85

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (10)
    As of 2014-07-25 02:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (167 votes), past polls