Home: Perl Programming Help: Advanced:
Newline (\n) Interpretations



griswald88
Novice

Feb 25, 2004, 7:14 AM


Views: 2408
Newline (\n) Interpretations

I have a routine that writes data from a scalar into a file with the following syntax:

print DATADIR "$data_line\n";

However, on some servers, once I download the data I get a file where each record is delimited by a carriage return + line feed (which is what I want), BUT on others I receive a file where each record is delimited by just a line feed (which is what I DO NOT want).

Any idea what is causing this or how I could write the lines to the file more consistantly?

Thanks!


davorg
Thaumaturge / Moderator

Feb 25, 2004, 7:38 AM


Views: 2407
Re: [griswald88] Newline (\n) Interpretations

perldoc perlport (particularly the section on newlines

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


griswald88
Novice

Feb 25, 2004, 1:53 PM


Views: 2402
Re: [davorg] Newline (\n) Interpretations

OK, here is a little more information, here is what I am doing on the Perl side (at this point the file is PERFECT):

if
(open (DATAMAIN, "$archive_file"))
{
#read the file into an array and close handle
@records=<DATAMAIN>;
close (DATAMAIN);

print "Content-type: application/octet-stream\n";
print "Content-disposition: attachment; filename=$archive_file\n\n";
print @records;
}

On the client, VB, on some machines (all platforms) a CR is stripped from the end of each record leaving behind a LF only, thus creating a file size difference. Any ideas now? Thanks again!!


davorg
Thaumaturge / Moderator

Feb 25, 2004, 11:31 PM


Views: 2401
Re: [griswald88] Newline (\n) Interpretations

You are quoting $archive file unnecessarily and you read all of the file into memory - which is probably a bad idea. I'd write that like this:

Code
if(open (DATAMAIN, $archive_file)) { 
#read the file into an array and close handle

print "Content-type: application/octet-stream\n";
print "Content-disposition: attachment; filename=$archive_file\n\n";
print while <DATAMAIN>;
}


But that won't solve your problem.

Is there any pattern to the browsers that are being used on the systems that exhibit the problem? Or perhaps browser versions?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


griswald88
Novice

Feb 26, 2004, 6:44 AM


Views: 2400
Re: [davorg] Newline (\n) Interpretations

Thanks for all of your help! I have finally found the answer or at least how to handle it. It turns out the PC's that were receiving this file size difference were running Perl from the perlis.dll rather than the Perl.exe. It appears as though the dll strips off the CR when downloading...once again thanks!