Your code is a snippet that is designed to work as part of a CGI script that you'd put on a web server and run via a web browser. The CGI script would be written to work with a framework called CGI::Application. So to run your code you'll need to install CGI::Application and a module called CGI::Application::Plugin::Output::XSV -- both are available at metacpan.org

Here's how I am able to get your snippet to work:

First I create a file named index.cgi which I put into a directory named /www/cgi-bin/MyOutputXSV

My perl executable (filename is perl) is in a directory called /opt; change the first line of the script to point to the installed perl executable file on your web server.

#!/opt/perl use strict; use warnings; use lib ( '/www/cgi-bin/MyOutputXSV' ); use MyOutputXSV; my $app = MyOutputXSV->new(); $app->run();
Next I create a file named MyOutputXSV.pm and put it into that same directory:
package MyOutputXSV; use strict; use warnings; use parent 'CGI::Application'; use CGI::Application::Plugin::Output::XSV qw(:all); # headers generated will be [ "first", "last", "phone" ] sub setup { my $self = shift; $self->run_modes( 'generate_report' => 'generate_report', ); $self->start_mode('generate_report'); } sub generate_report { my $self = shift; return $self->xsv_report_web({ values => [ { first_name => 'Jack', last_name => 'Tors', phone => '555-1212' }, { first_name => 'Frank', last_name => 'Rizzo', phone => '555-1515' }, ], fields => [ qw(first_name last_name phone) ], headers_cb => sub { my @h = @{ +shift }; s/_name$// foreach @h; return \@h; }, }); } 1;
Next I change the Linux file permissions on index.cgi to be 705 (which lets my Apache web server read and execute the script) and then I run the script by entering https://mysitename.com/cgi-bin/MyOutputXSV/index.cgi into my web browser.

The script then returns data as a binary file named download.csv, which my browser detects and uses to present a popup box to me that asks what program I'd like to use to open it. I have Excel on my Windows 10 PC so that's what I tell the browser. Then Excel opens and I see the data in a 3x3 set of cells:

first last phone Jack Tors 555-1212 Frank Rizzo 555-1515

In reply to Re: Example using CGI::Application::Plugin::Output::XSV by davebaker
in thread Example using CGI::Application::Plugin::Output::XSV by logangha

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.