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

Nobody in particular
EDAVIS [...]

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

Subject: Suggested policy: forbid ^ and $
Most perl programmers write things like if ($str =~ /^keyword$/) { ... } expecting it to be a literal match against 'keyword'. They think that $ matches the end of the string. But it doesn't; this program accepts "keyword\n" the same as "keyword". If you use the /m flag always, as another policy suggests, then ^ is supposed to match the beginning of a line and $ the end. But /^/m is also hard to understand and bug-prone. I suggest that people should say what they mean and use \A for the beginning of the string, \z for the end, and if really wanted \Z for end-ignoring-final-newline. Now there is already a policy RegularExpressions::RequireLineBoundaryMatching. This proposed policy does not conflict with that, but it does make it obsolete in a way; if you do not use the ^ and $ anchors then it doesn't matter whether you use the /m modifier or not. For more details, see <>, quoted below:
Show quoted text
>I am mystified as to the circumstances under which one might actually >want the behaviour of /$/ (without /m) or /^/m. Certainly they can be >correctly used, with a bit of care, but as far as I can see they never >completely match the actual semantics of what constitutes a line start >or end.
Show quoted text
>/^/m is so difficult to understand that its >own implementors have trouble with it. It was documented incorrectly >in perlre for years, until I discovered the undocumented /(?!\z)/ bit >of its behaviour and pointed it out (bug #27053, resolved by a >documentation change in 5.10).
Subject: Re: [ #38292] Suggested policy: forbid ^ and $
Date: Thu, 07 Aug 2008 12:45:21 -0500
From: Elliot Shank <>
See RegularExpressions::ProhibitFixedStringMatches.
Show quoted text
>See RegularExpressions::ProhibitFixedStringMatches.
A good policy, but not quite the issue addressed here. For example to crudely match an HTML heading start tag, /^<h[1-6]>$/ is buggy - it allows a trailing newline. /\A<h[1-6]>\z/ is correct (for the purpose of this example).

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

Please report any issues with to