[H-GEN] couple of small perl questions

Byron Ellacott bje at apnic.net
Thu Jan 16 20:52:44 EST 2003


[ Humbug *General* list - semi-serious discussions about Humbug and     ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]

On Fri, 2003-01-17 at 11:34, Byron Ellacott wrote:
> $line =~ s/\r\n/\r/;  # should do it

Gauche I know, but I forgot to footnote this.

\r\n is a nonportable way to do this.  If you want to be serious about
it, you should use \015\012 so that \n doesn't get expanded to \r\n on
machines where that is appropriate.  But you'll also have to make sure
you're on an ASCII machine, because on an EBCDIC machine 012 and 015
aren't what you'd expect ...

my $CRLF = "\015\012";
$CRLF = "\r\n" if ("\t" ne "\011");

There's sometimes more to it than that, too, but that will give you a
reasonably portable solution. ;)

-- 
Byron Ellacott <bje at apnic.net>
APNIC

--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.  See http://www.humbug.org.au/



More information about the General mailing list