Beautiful! The following code is now in place and, having tested it with both Windows and Mac, it is working exactly as desired. Thank you so much for taking time to help with this. I have learned a few things.

None of the fields should ever contain tabs, so that should be no issue. I always use strict, but only use warnings while troubleshooting. It's presently commented out to save space in the log files (when working with UTF8, wide character warnings seem to appear for no reason at times, when everything is working properly, and sometimes I get the uninitialized errors that are also extraneous--and the logs simply aren't monitored often enough to make filling them with such errors useful). For what it's worth, when the script with this subroutine is run, the script is adding a "wide character" error to the error log even with warnings turned off, despite the fact that everything is working beautifully, and the zip file that is created contains perfect text in an Asian language. The error comes from having Asian text in one of the HTML headings for the page, even though the "use utf8;" pragma is in place. To avoid it I'd probably need to convert that text to HTML-entities which makes it totally unreadable in my code, and ugly. I'd rather get useless warnings.

sub exportdatabase { #INCOMING GLOBAL VARS: $statement, $db_export_file, # $cur_date, $cur_time, $OS, $table, $quest fork: { my ($recnum,$revnum,$book,$chap,$verse,$text) = ''; my @resp = (); my $encoding = "UTF-8"; my $zipdata = ''; my $CRLF = "\n"; my $zipfile = "$db_export_file.zip"; my $q = CGI::Simple->new(); my $z = IO::Compress::Zip->new(\$zipdata, Name => "$db_export_file" ) or die "zip failed: $ZipError\n"; if ($OS eq "Windows") { $CRLF = "\r\n"; } $statement = qq| SELECT a.RecordNum, a.RevisionNum, a.Book, a.Chap +ter, a.Verse, a.Text from $table a INNER JOIN (SELECT RecordNum, max( +RevisionNum) RevisionNum FROM $table GROUP BY RecordNum) b USING (Rec +ordNum,RevisionNum); |; &connectdb('exportdatabase'); $z->print( encode( $encoding, "RECORD#\tREVISION#\tBOOK#\tCHAP#\tV +ERSE#\tTEXT, AS EDITED BY: $curdate $curtime (Pacific Time), EXPORTED + IN $OS FORMAT$CRLF", Encode::FB_CROAK|Encode::LEAVE_SRC ) ); while ( ( $recnum, $revnum, $book, $chap, $verse, $text ) = $quest +->fetchrow_array() ) { $z->print( encode( $encoding, "$recnum\t$revnum\t$book\t$chap\ +t$verse\t$text$CRLF", Encode::FB_CROAK|Encode::LEAVE_SRC ) ); } $z->close(); print $q->header( -type => 'application/zip', -Content_Disposition => qq{attachment; filename="$zipfile"}, -Content_Length => length($zipdata) ); binmode STDOUT; # just to play it safe print $zipdata; } # END fork } # END SUB exportdatabase

In reply to Re^6: Correct Perl settings for sending zipfile to browser by Anonymous Monk
in thread Correct Perl settings for sending zipfile to browser by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.