in reply to Re: What is clear code ?
in thread What is clear code ?

update: In the original node, I'm probably not as clear I should be that much of the second sub is ovid's

Yes, while the chomp better than the no chomp, it is not perfect. If the string is something like "asadf\r\n" and the OS is \r\n orriented, the chomp gives us "<p>asdf</p>" instead of "<p>asdf</p><p></p>". If we are processing the string on a \n orriented OS, We are out of luck...

If I understand  perldoc perlre the "/s" or "!s" at the end of the regular expression means "Treat string as single line. "

However, in tadman's node, I'm not getting how s/\r\n//s ( or s!\r\n!!s ) means "take off the \r\n at the end of the string" ???



email: mandog

Replies are listed 'Best First'.
Re: Re: What is clear code ?
by abstracts (Hermit) on Apr 29, 2002 at 03:21 UTC
    tadman said:
    $fix =~ s!\r\n$!!s;
    Notice the '$' mark in the line: it anchors the '\r\n' to the end of string. Meaning, replace \r\n only if it appears as the last thing in the string.