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:
84734
Status:
new
Priority:
Low/Low
Queue:

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

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



Subject: Suggested policy: while (<$fh>) inside subroutine
The following subroutine looks harmless enough: sub count_lines { my $filename = shift; open my $fh, '<', $filename or die; my $count = 0; while (<$fh>) { ++$count; } return $count; } However it is not safe to use in general because it will trample on the caller's $_. This is an easy mistake to make, because the more common foreach (...) is safe and won't affect the caller's $_. The somewhat less common while (<$fh>) construct looks like it works similarly to foreach (...) but has this hidden side effect. Perlcritic should warn about use of while (<$fh>) in a subroutine unless $_ has been explicitly localized first.


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.