Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Need help in translating the following php code to perl

by nadarajan (Novice)
on Oct 29, 2013 at 20:33 UTC ( [id://1060218]=perlquestion: print w/replies, xml ) Need Help??

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

<?php header('Content-type: application/vnd.ms-excel'); header("Content-Disposition: attachment; filename=BOBreport.xls"); header("Pragma: no-cache"); header("Expires: 0"); echo $_REQUEST['hiddenExportText']; ?>
The most important line is header("Content-Disposition: attachment; filename=BOBreport.xls"); I need to have it in my perl script to export a html table data to Excel Thanks

Replies are listed 'Best First'.
Re: Need help in translating the following php code to perl
by davido (Cardinal) on Oct 29, 2013 at 22:49 UTC

    Use the CGI module if you're doing CGI with Perl. It provides a header() method, and a param() method, which mostly work as you expect. Read the POD for details. It's been years since I last messed around with plain old CGI, and I don't even have a CGI-enabled environment configured at the moment that I can use for testing.

    use CGI; my $q = CGI->new; print $q->header( -type => 'application/vnd.ms-excel', -Content-disposition => 'attachment; filename=BOBreports.xls', -pragma => 'no-cache', -expires => 'now', ); print $q->param('hiddenExportText'), "\n";

    The header method conveniently passes through parameters that it doesn't know what to do with. For example, '-pragma' becomes 'Pragma: '

    For the brave new world in web work, see Mojolicious or Mojolicious::Lite, or Dancer.


    Dave

Re: Need help in translating the following php code to perl (search!)
by Anonymous Monk on Oct 30, 2013 at 00:47 UTC
Re: Need help in translating the following php code to perl
by sundialsvc4 (Abbot) on Oct 30, 2013 at 00:15 UTC

    Uhh ... gotta say it, but ...

    The most-significant textual clip from the OP, IMHO, is this one:   The most important line is header("Content-Disposition: attachment; filename=BOBreport.xls"); I need to have it in my perl script to export a html table data to Excel.

    It quite-frankly appears to me that the OP is most-interested in the output of the aforesaid (PHP ...) code.   If this is indeed the case, then there is in fact no actual requirement to “translate the following PHP code to” ... (anything!)

    If you are only concerned with the (HTML) output of a computer program, then you do not care in the slightest what programming-language was originally used to generate that output.

    If the Perl program that you contemplate is destined to be a client of the program that (somehow ...) produces the “HTML table data,” this Perl program need only be concerned with “how to correctly parse this HTML data, regardless of its source.”

    On the other hand, if the Perl program that you contemplate is destined to replace entirely the aforesaid program as “the root-source of the data being sought” ... then both PHP and the HTML that it now produces become irrelevant.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1060218]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-16 15:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found