creating unix-like text files in windows

H

Huppu

Hi!

I'm trying to create unix-like text files in Windows. The biggest issue is
that I need to use only linefeed instead of carriage return+linefeed. It
tried this with hex value \x0A, but it still did norman windows linebreak
LF+CR(like I was using \n).

Does anyone have any solution for this? Creating these files in unix is not
a solution... ;-)

<-_->
 
P

Pedro Graca

Huppu said:
I'm trying to create unix-like text files in Windows. The biggest issue is
that I need to use only linefeed instead of carriage return+linefeed. It
tried this with hex value \x0A, but it still did norman windows linebreak
LF+CR(like I was using \n).

Does anyone have any solution for this? Creating these files in unix is not
a solution... ;-)

newbie answer -- probably gurus have a better way to do it

check binmode
perldoc -f binmode

example program
#!/usr/bin/perl -w
use strict;

open my $FILE, ">unix.txt" or die $!;
binmode $FILE;

print $FILE "one\n";
print $FILE "two\n";
print $FILE "three\n";
print $FILE "four\n";
print $FILE "five\n";
close $FILE;



HTH
 
B

Ben Liddicott

Hi Huppu,

By default, the translation from LF to CRLF happens in the IO layer.

You turn it off like this:

binmode FILEHANDLE;

Or by specifying binary mode when opening, which is a better idea.

For more information:
perldoc -f binmode
perldoc -f open
perldoc -f sysopen

perldoc IO::File
perldoc PerlIO

Cheers,
Ben Liddicott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top