Remove quotes from hash key with expression

93 Views Asked by At

I have:

$rejected->{join ',', @needed}++ unless @filtered;

but the perlcritic complains with

title=Hash key with quotes - severity 5::[HashKeyQuotes] Avoid useless quotes

Obviously I can lower the severity, but I wonder whether there is any other way?

Two which I can think of are:

  • use a constant
  • move the whole join outside the {}.

Is there any other approach?

2

There are 2 best solutions below

2
Rawley Fowler On

I believe it's not within PBP to use quotes like that on join. Try:

$rejected->{join(q{,}, @needed)}++ unless @filtered;

I don't see any perlcritic warnings with this.

In general though, I would block this on a code review, and ask for you to move the join to a new lexically scoped variable, with a decent name.

4
ikegami On

If you get that critic from that code, it's obviously a bug in the HashKeyQuotes policy since you don't have useless quotes around hash keys.

Flag it to be ignored. Contorting your code to silence perlcritic defies the whole point of using perlcritic.