开发者

Formats and end of line characters

开发者 https://www.devze.com 2023-02-07 12:01 出处:网络
Is开发者_如何学Python there any way to change the end of line character for a perl format? I need to output a file in DOS format and it looks like write does not obey what is in the $\\ variable.I\'m

Is开发者_如何学Python there any way to change the end of line character for a perl format?

I need to output a file in DOS format and it looks like write does not obey what is in the $\ variable.


I'm assuming you are trying to do this on a non-Windows platform?

You just need a :crlf layer on your filehandle, e.g.:

open FOO, "> :crlf", "foo.txt" or die "error: $!";
format FOO=
hi
there
.
write FOO;

You can apply layers to existing filehandles using binmode:

binmode STDOUT, ":crlf";
0

精彩评论

暂无评论...
验证码 换一张
取 消