CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



griswald88
Novice

Feb 25, 2004, 7:14 AM

Post #1 of 5 (1312 views)
Newline (\n) Interpretations Can't Post

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

Post #2 of 5 (1311 views)
Re: [griswald88] Newline (\n) Interpretations [In reply to] Can't Post

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

Post #3 of 5 (1306 views)
Re: [davorg] Newline (\n) Interpretations [In reply to] Can't Post

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

Post #4 of 5 (1305 views)
Re: [griswald88] Newline (\n) Interpretations [In reply to] Can't Post

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

Post #5 of 5 (1304 views)
Re: [davorg] Newline (\n) Interpretations [In reply to] Can't Post

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!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives