|Just another Perl shrine|
Re^2: Use of the m/.../g idiom in list context (formatting MAC addresses) (use of fat commas)by grinder (Bishop)
|on Jan 17, 2005 at 14:36 UTC||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:
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
much harder to parse than
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