Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

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

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 learning in the Monastery: (5)
As of 2024-04-24 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found