What a bunch of poopy answers

Hi,

You need to organize your code (make subs with meaningful names), its like 2nd day programming stuff that people forget about until a framework slaps them in the face with the requirement, but you don't have to be unconcious about it, take charge of your code, give it name, like you would a stuffed animal, it makes playtime all the more interesting

Like this, this is you foo.cgi or foo.pl

#!/usr/bin/perl -- use strict; use warnings; use MyStuff; Main( @ARGV ); exit( 0 ); sub Main { MyStuff::RunCGI({ 'dbconfig' => { } }); ## print MyStuff::ThisPage( CGI->new({ page => 'thisone', debug=>1, +in => 'making sure this works, dev, debug'} ) ); }

This is your MyStuff.pm

package MyStuff; use HTML::Template; use strict; use warnings; use CGI(); sub MyStuff::RunCGI { my $q = CGI->new; my( $headers, $body ) = MyStuff::DispatchCGI( $q ); print $headers, $body; } sub MyStuff::DispatchCGI { my( $q ) = @_; my $page = $q->page || 'default'; $page = 'ajax' if $q->request_method eq 'POST' and ...; return ThisPage( $q ) if $page eq 'thisone'; return ThatPage( $q ) if $page eq 'thatone'; return AjaxPage( $q ) if $page eq 'ajax'; } sub MyStuff::ThisPage { my( $q ) = @_; my $template = HTML::Template->new ...; $template->param( foo => scalar $q->param('foo') ); ... ... return $q->headers, $template->output; } sub MyStuff::AjaxPage { my( $q ) = @_; ... return $headers, $body; }

Your html template should include/link these two javascript files jquery.js myecho.js you can get example myecho.js from Mojolicious::Lite +and jQuery +AJAX + Mojo::Template, it uses jquery to make a http request to a url and retrieve some data from it, and update the webpage/dom/display/divtag the user sees

more subs, cgi101, learn about the internet


In reply to Re: HTML::Template Alternative to output() (more subs , cgi101) by Anonymous Monk
in thread HTML::Template Alternative to output() by amitsq

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.