The idea is to refactor the portions of your code that can be shared by A.cgi and B.cgi. Consider the following:

my $data = 'pretend this is a complex data structure'; my $is_web_browser = 1; if ($is_web_browser) { print qq(<span color="red">$data</span>\n); } else { print qq(\e[0;31m$data\e[0m\n); }
For this example, sometimes we want to decorate our data one way for one kind of client and another way for another kind of client. Rather than use one file for producing/publishing the data to be displayed as well as decorating that for a Unix command line AND a CGI "web page" ... why not refactor into one module that any number of formatters can consume?

file: SomeModule.pm

package SomeModule; use strict; use warnings; sub get_data { return 'pretend this is a complex data structure'; } 1;

file: app.cgi

use strict; use warnings; use SomeModule; my $data = SomeModule::get_data(); print qq(<span color="red">$data</span>\n);

file: app.pl

use strict; use warnings; use SomeModule; my $data = SomeModule::get_data(); print qq(\e[0;31m$data\e[0m\n);

This is a very simple and distilled example, but hopefully you see how different apps can reuse the same modules without actually executing each other as a script.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re: cgi page calling another cgi when submitting form but does not returns error only to web server log and not to browser. by jeffa
in thread cgi page calling another cgi when submitting form but does not returns error only to web server log and not to browser. by chidori

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.