On 2008.01.12 01:12:42 -0800, Eric Wong wrote:
Junio C Hamano [off-list ref] wrote:
quoted
Is it only me who finds that
($var) = ($var =~ m{^(any regexp)$}) or die "message"
is extremely a roundabout and hard-to-read way to say:
if ($var !~ m{^(the same regexp)$} {
die "message";
}
which is much easier to read?
The statements are not equivalent, however. I'd have to add
$var = $1;
too, because I needed to extract what was inside the ( ) since the '$'
doesn't catch the trailing newline, either. I also couldn't find any of
the /sm, /m, /s switches useful for making '$' not accept the trailing
newline, either.
The \z assertion will do, eg m/^foo\z/ will only match exactly "foo",
not "foo\n". As it is a zero-width assertion, you can also write
m/^foo\z$/ if you prefer that.
Björn