Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi PerlMonks

I'm trying to generate a file that users can download - it is basically just pulling data from mysql and printing it out.
What I did so far was to put the content-type header as text/plain which works great it prints out to a download for users, but when I try to put each row of data on a newline using the \n char It just shows up as an unrecognized charachter and they are all bundled together.

If anyone could point me in the right direction that would be great, Thanks.

Replies are listed 'Best First'.
Re: Generating Files
by Joost (Canon) on May 10, 2002 at 16:11 UTC
    Try this:

    foreach my $line (@data) { print "$line\015\012" }

    Explanation: you need to send \r\n to the client over http, but the definition of \r and \n are different for each client, so using "\015\012" is safer..

    -- Joost downtime n. The period during which a system is error-free and immune from user input.
      If this is indeed HTML, sticking a <p> in the print statement might be a Good Idea, too. (Or a separate print p(); if using CGI.pm)
A reply falls below the community's threshold of quality. You may see it by logging in.