perlquestion
betterworld
<p>Hi monks,</p>
<p>apparently, <code>/.*\z/</code> tests whether a string ends in a newline:</p>
<code>
$ perl -e 'print "there is no newline\n" if "foo\n" =~ /.*\z/'
$ perl -e 'print "there is no newline\n" if "foo" =~ /.*\z/'
there is no newline
</code>
<p>I find this very strange. In my opinion, this regular expression should <i>always</i> match. Every string, even "foo\n", has an end (\z), and since .* matches zero or more horizontal characters, it should always match the empty string before the end of the string. However, it doesn't, as you can see in the first one-liner.</p>
<p>I found this RE in the code of [cpan://Log::Handler] by [bloonix] and I'm wondering why it works.</p>
<p>I've tested it in perl versions 5.8.8, 5.005_03 and 5.9.4.</p>
<p><i><b>Update:</b></i> This perl bug is now fixed (see below). Thanks to [demerphq].</p>