Skip Menu |
 

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: 0/
Queue: Perl-Critic

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

Bug Information
Severity: Wishlist
Broken in: 1.115
Fixed in: (no value)



Subject: Suggested policy: forbid test ($#foo > -1)
Download (untitled) / with headers
text/plain 367b
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>
Download (untitled) / with headers
text/plain 380b
On Fri, Jul 1, 2011 at 10:50 AM, EDAVIS via RT <bug-Perl-Critic@rt.cpan.org>wrote: There should be a policy to pick up comparisons of $#foo against -1 and Show quoted text
> 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 is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

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