homepage Welcome to WebmasterWorld Guest from 54.226.213.228
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Create a Unix file on Windows system
How to create
balour




msg:3333209
 8:07 pm on May 7, 2007 (gmt 0)

I run a Perl script on a Windows system and i need to create a Unix file. I use the following line to create the file:

open (OUT,">$out") ;

$inline = join ("\",$mast[0],$mast[1],$mast[2]) ;

print OUT "$inline\n" ;

close (OUT) ;

The final result is a DOS file, but I need a UNIX file. The result must be transfert to another system.

Gilles

 

perl_diver




msg:3333259
 9:19 pm on May 7, 2007 (gmt 0)

that should be fine for unix, whats the problem?

balour




msg:3333284
 9:58 pm on May 7, 2007 (gmt 0)

That the problem. The final result is a DOS file and not a Unix file. I use Activestate for Perl interpreter, Windows XP and Sambar as the server.

phranque




msg:3333323
 10:44 pm on May 7, 2007 (gmt 0)

you could be confusing the file with the file system.
what happens when you transfer that file to a *nix-type file system?

rocknbil




msg:3333441
 3:42 am on May 8, 2007 (gmt 0)

When you use perl to create a file on a DOS system, it will create the DOS end-of line character. I cannot remember the specifics, but I **think** this is a CRLF (carriage return + line feed.) Unix-based systems create only the single line feed.

I first experienced this way back in the day when I did my scripts in NotePad, uploaded them ASCII to a server, and they would 500 error. A wise admin recommended I find an editor that saves in Unix format and volia, the problem went away.

Those of you more adept at perl-y stuff may have better recommendations than below. Try this, which is the octal equivalent of line feed:

$CRLF = "\x0d\x0a";

print OUT "$inline$CRLF" ;

It doesn't work if you put \x0d\x0a in the print command for some reason. Yo might also try just \x0d and \x0a independently.

Of course it's possible none of it will work, since you're creating the file in DOS it may try to adhere to the OS in printing out the file, but it's worth a try. If all else fails you could open it in HomeSite or some other program that saves in Unix format and do a save as.

perl_diver




msg:3333496
 6:16 am on May 8, 2007 (gmt 0)

He is using perl to write the file and using a newline as the line ending. Windows is not going to add a carraige return to that. There should be no problem with the line endings when used on a nix box. Something else is wrong or the OP is confused.

phranque




msg:3333519
 7:06 am on May 8, 2007 (gmt 0)

you might need to use the binmode() function [perldoc.perl.org] in this case.

Dabrowski




msg:3333587
 9:40 am on May 8, 2007 (gmt 0)

Yes, DOS uses
0D0A for end of line CR + LF. UNIX only uses 0A. Annoys the hell out of me when a friend of mine sends me code!

You'll need to binmode OUT as follows:

open (OUT,">$out");
binmode OUT;

Do that immediately. Then instead of doing:
print OUT "$inline\n";

Try:
print OUT "$inline\x0a";

I think \x0a is the same as \r, on DOS you're supposed to use \r\n. I vaguely remember in the olden days I used to have to do that, now \r is inserted automatically.

Infact, thinking about it, you shouldn't might not need to binmode OUT either if you can use \r.

Try those things and let us know how that goes.

balour




msg:3333791
 2:50 pm on May 8, 2007 (gmt 0)

It's work now.

I just add
binmode OUT ;
after
open (OUT,">$out") ;

I stay with

print OUT "$inline\n" ;

for each line and this work fine.

Thank for advise.

Dabrowski




msg:3333797
 3:02 pm on May 8, 2007 (gmt 0)

I think then by changing to a binary stream, the DOS filesystem is not adding the \r (0x0D) that unix doesn't like.

A good learning experience for all!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved