note
ikegami
<blockquote><p><i>Would any line produced by evaluating the <$fh> expression ever end in \r\n?</i></blockquote>
<p>On Windows? It would require CR CR LF in the file (assuming default <c>$/</c> and IO layers). Extremely unlikely.
<p>Elsewhere? It would require CR LF in the file (assuming default <c>$/</c> and IO layers). Possible.
<blockquote><p><i>I think <c>s{ $/ \z }{}xms</c> would work</i></blockquote>
<p>Well, that should be <c>s{ \Q$/\E \z }{}xms</c> (and <c>/m</c> and <c>/s</c> are useless) to be equivalent to the <c>chomp</c>.
<p>And if <c>$/</c> hasn't been changed, <c>s/\n\z//</c> could be used (since <c>$/</c> defaults to LF on all systems).
<p>But if I was going with a regex pattern, I'd go with <c>s/\s+\z//</c>. Handles <c>\n</c>, <c>\r\n</c> and other trailing whitespace. (TSV files being an exception.)
11119056
11119088