Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

getting module output in a cgi file

by rjsaulakh (Beadle)
on Dec 17, 2005 at 11:35 UTC ( #517468=perlquestion: print w/ replies, xml ) Need Help??
rjsaulakh has asked for the wisdom of the Perl Monks concerning the following question:

how do i get the o/p of this module insdie a cgi file i want to display the hyperlinks to the pages

sub pageNumbers { $total_pages = int (($#matches) / $total_records_page); #Integer +division $remainder = ($#matches) % $total_records_page; if ($remainder) { $total_pages++; } if($total_pages) { print <<"END"; <table cellpadding="0" cellspacing="0" bor +der="0" width="100%"> <tr> <td class="smtxt"> END print "<b>Page&nbsp;</b>"; for $i (1 .. $total_pages) { if ($i == $page) { print "<b>$i</b>"; } else { print "<a href=\"winner.cgi?page=$i&period=$period\">$ +i</a>"; } if ($i != $total_pages) { print "&nbsp;|&nbsp;"; } } print "<!-- '$total_pages' '$remainder' --></td></tr></table>\ +n"; } } exit(0);

Comment on getting module output in a cgi file
Download Code
Re: getting module o/p in a cgi file
by bradcathey (Prior) on Dec 17, 2005 at 13:18 UTC

    Like the good monks have been telling you, use a templating system like HTML::Template and a lot of your issues will dissolve away. Get the HTML out of your CGI. It's sooooo much easier.

    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: getting module output in a cgi file
by Joost (Canon) on Dec 17, 2005 at 15:59 UTC
    Remove the exit statement or you won't even be able to use the module. also, I'd STRONGLY suggest using strict, lexical variables and pass the values as function arguments instead of relying on vars that are declared (or not) SOMEWHERE else.

    then do something like:

    use ModuleName; # ... pageNumbers($total_pages,$matches,$total_records_page, @and_whatever_o +ther_variables_you_need);
Re: getting module output in a cgi file
by Your Mother (Canon) on Dec 17, 2005 at 19:43 UTC

    Don't forget that using abbreviations like "o/p" can be confusing to readers who aren't sure what they mean especially in this case when I believe you actually meant G.O. (Kidding!)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://517468]
Approved by Joost
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2014-11-21 03:12 GMT
Find Nodes?
    Voting Booth?

    My preferred Perl binaries come from:

    Results (104 votes), past polls