Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I just wonder if '=>' is good choice?

A legitimate question. Let me try and explain.

comma (,) and fat arrow (=>) can be used pretty much interchangeably. The main difference is that fat arrow forces string context on its left hand argument. This is notably useful for hash keys that are matched by \w+, since it means you can do away with single quoting of keys. Less noise, less fuss, less chance of error.

In the case of join, I can make a pretty strong argument for why the use of fat comma is a good idea as well. Look at the prototype for join:

perl -le 'print prototype "CORE::join"' # prints '$@'

That is, join takes a scalar and a list. Which makes sense when you know what join does. It takes the first argument and applies it to the rest of the arguments. Thus, the use of fat arrow here serves as a discriminant to better help you distinguish between the first argument and the rest of the list. In my code, one of the most frequent characters I use to join arrays is... a comma! From a whitespace point of view, I like my commas to cuddle up right behind the preceding argument, which means I find that

join( ',', '-', '.', '"' );

much harder to parse than

join( ',' => '-', '.', '"' );

Regardless of whether the above is a highly contrived example, just the apostrophe, comma, apostrophe, comma by itself gives me a headache. This doesn't mean you should go overboard and use fat comma anywhere and everywhere, but I think that in the case of join the result is worth it.

- another intruder with the mooring in the heart of the Perl

In reply to Re^2: Use of the m/.../g idiom in list context (formatting MAC addresses) (use of fat commas) by grinder
in thread Use of the m/.../g idiom in list context (formatting MAC addresses) by grinder

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 scrutinizing the Monastery: (4)
    As of 2018-01-23 02:35 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (238 votes). Check out past polls.