8

Follow code is not accepted by Critic, severity 4:

return {
    'debug'  => $debug,
    'identifier' => $identifier
};

I get this error:

# Perl::Critic found these violations in "filename.pl":
# Comma used to separate statements at line 356, column 3.  See pages 68,71 of PBP.  (Severity: 4)

But this code is accepted without any remark:

my $result = {
    'debug' => $debug,
    'identifier' => $identifier
};

return $result; 

Is it really better to write my return using a temporary variable, or is the critic wrong in detecting a Comma used to separate statements while I'm just constructing and returning a hashref?

Charles
  • 50,943
  • 13
  • 104
  • 142
Konerak
  • 39,272
  • 12
  • 98
  • 118
  • WOuld it help if you write return `({ .... });` ? – Ingo Feb 02 '12 at 10:49
  • I cannot reproduce this behaviour. What version of `Perl::Critic` are you using? – Borodin Feb 02 '12 at 11:06
  • I cannot reproduce the problem: `perlcritic --brutal -s ValuesAndExpressions::ProhibitCommaSeparatedStatements so9110962.pl␤so9110962.pl source OK` Perhaps upgrade PPI and Perl::Critic? – daxim Feb 02 '12 at 11:08
  • I suggest using a temp array then return its address like `my %ans = { ...} ; return \%ans`, you are indicating that your are returning an hashref and not a function block. – MUY Belgium Aug 21 '14 at 12:18

1 Answers1

7

I found this bug in version 1.105, it is gone in version 1.116. It got fixed somewhere in between there.

The fix is not mentioned in the change logs, but PPI changes are mentioned. May have been a PPI error.

Bill Ruppert
  • 8,956
  • 7
  • 27
  • 44
  • Thanks, upgrading to the last version indeed helped (and created a whole new list of criticisms for code that previously passed, too - yay! :]) – Konerak Feb 02 '12 at 17:58