Philosophical answer: You should separate the model from its representation. → MVC

Assuming, your CGI returns HTML, it is not a good idea to scrape the information back. Let your code call the sub for data and let the sub return the data only. Let your CGI-sub call the same sub and let it render the result in a specific format that is returned via HTTP.

IF your CGI returns data in a format that is parsable (i.e. JSON or YAML or XML or ...), then there's the alternative to call the CGI via HTTP (LWP::UserAgent) and deserialise the result. That's not too performant, though and requires additional error-handling. On the pro-side, data can be retrieved from a remote server.

Hope that helps. I might completely misunderstood your question, though ;-)

Update: Clarification in form of code fragments:

#-- the sub that computes the data (@result) only from it's parameters + (@pars) # Using @result as an array is just for simplicity. It could be hash +-ref or an object # or whatever your expected result fits into... # sub get_result { my (@pars) = @_; ..... return @result; } #-- here's your CGI handler # sub cgi_handler { ... my (@pars) = ... #-- get params from HTTP request my (@result) = get_result( @pars ); ... #-- render HTTP-response from your + @result } #-- somewhere else in your code... where your original question came f +rom... # Instead of a regular function, an object method or a class method +or an AUTOSUB etc. # could be called. # sub somewhere_else { #-- no worry to call cgi_handler(), just call @result = get_result( @pars ); ... }


In reply to Re: CGI Action call by Perlbotics
in thread CGI Action call by tultalk

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.