Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id:
69232
Status:
open
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
EDAVIS [...] cpan.org
Cc:
AdminCc:

BugTracker
Severity:
Wishlist
Broken in:
1.115
Fixed in:
(no value)



Subject: Suggested policy: forbid test ($#foo > -1)
Inexperienced perl programmers may use $#array to test whether @array is empty: if ($#array > -1) { ... } This would be more idiomatically written as if (@array) { ... } or perhaps if you want to be explicit if (scalar(@array) > 0) There should be a policy to pick up comparisons of $#foo against -1 and suggest a better way to test array emptiness.
Subject: Re: [rt.cpan.org #69232] Suggested policy: forbid test ($#foo > -1)
Date: Fri, 1 Jul 2011 11:58:23 -0700
To: bug-Perl-Critic@rt.cpan.org
From: "Thalhammer, Jeffrey" <jeff@imaginative-software.com>


On Fri, Jul 1, 2011 at 10:50 AM, EDAVIS via RT <bug-Perl-Critic@rt.cpan.org> wrote:

Show quoted text
There should be a policy to pick up comparisons of $#foo against -1 and
suggest a better way to test array emptiness

Ooo, I like that idea!
 
Show quoted text
or perhaps if you want to be explicit

   if (scalar(@array) > 0)

Personally, I would forbid that too.  But that may be going too far.

-Jeff



This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.