Since you're actually assigning your hash key a value in the map statement, it only makes sense to use the fat comma (=>) in this context, but operationally, there's no difference.
-stevieb
| [reply] |
I don't see that as separate statements
Perl::Critic doesn't understand 100.00% of Perl. But then again, if perlcritic is misreading that statement, other people might too. perlcritic doesn't complain with both {$_=>0} or {($_,0)}, and those make it a little more obvious what you're trying to do.
Anyway, to get an explanation from perlcritic, add the option --verbose 11:
$ perlcritic -3 --verbose 11 1129720.pl
Comma used to separate statements at line 7, near '$_,0'.
ValuesAndExpressions::ProhibitCommaSeparatedStatements (Severity: 4)
Perl's comma statement separator has really low precedence, which
leads to code that looks like it's using the comma list element
separator not actually doing so. Conway suggests that the statement
separator not be used in order to prevent this situation.
...
| [reply] [d/l] [select] |
To me, the “only” real value of perlcritic is ... “nonetheless, valuable!” The tool is actually pretty good at pointing out things in Perl source-code which, although syntactically valid, are likely to be mis-read by your fellow humans. It parses through the source-code symbol by symbol, “pedantically, as only a digital computer can do,” in order to ferret-out things that a human might easily mis-read “at a glance.”
Frankly, I tend to subscribe to the school of thought that says, “there is no such thing as being too obvious.” If perlcritic suggests a different way of saying something, that might be a little less likely to be misunderstood “at a glance,” then perhaps it has fulfilled its purpose. Any human being would probably gloss-over “that comma” without giving it any second thought ... and, as a result, perhaps ... misunderstand it. Therefore, maybe(!) it is a good idea to make the change suggested.
Obviously, tools like perlcritic are just that: tools, not oracles. Take them with a healthy grain of salt. (After all, they’re only ones and zeros.) But ... don’t dismiss them. The folks who wrote them, did so with a purpose.
| |
I don't see that as separate statements -- I can get rid of the complaint by changing comma to => but is there any point?
Why are you using perlcritic?
See Perl::Critic::Policy::ValuesAndExpressions::ProhibitCommaSeparatedStatements - Don't use the comma operator as a statement separator.
Using perlcritic by severity level is about as pointless as it gets -- its all opinion, you still have to decide which opinions you value and agree with
| [reply] |
Thanks.
I'm new to perlcritic and after working on default warnings I thought I'd step up the sensitivity.
| [reply] |
| [reply] |