http://www.perlmonks.org?node_id=575111

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

Hi monks, When i write the CGI output to an excel file by using the below code it works fine.
#!/usr/bin/perl -w use CGI; use strict; print <<test_header; Content-type: application/msexcel Content-Disposition: attachment; filename= test.xls ID;PWXL;N;E P;PGeneral P;P0 P;P0.0 P;P0.00 test_header
But when i write the above coding by inserting a line between the print statement and the content type as shown i get the file printed directly in the browser, not in the excel format. I don't know the reason for that. So Monks your valuable thoughts in the above. Thanks.
print <<test_header; Content-type: application/msexcel Content-Disposition: attachment; filename= test.xls ID;PWXL;N;E P;PGeneral P;P0 P;P0.0 P;P0.00 test_header

20060927 Janitored by Corion: Added code tags, as per Writeup Formatting Tips