qazxswcde has asked for the wisdom of the Perl Monks concerning the following question:

New to perl
s_page(); if(param("option") == 'login') { l_page(); } else { r_page(); } foot();

problem is all 3 functions display forms and i want them to display one after the other not in the same page. So first i want to display a page showing only s_page then i want to display a page showing ethier l_page or r_page depending on what you input. how is this done. The page keeps reseting making a if statment difficult i have tried using a "lexicon value but it doesnt seem to be working. Keeps displaying the first screen over and over again.

#!/usr/bin/perl use strict; use warnings; BEGIN{my $donce = 0; sub incr{ $donce++;} sub getdo{return $donce}} use LWP::Simple; use CGI qw/:standard/; print "Content-type: text/html\n\n"; had(); #lets me know if user has selected a option yet if(getdo() == 0) {s_page(); incr();print getdo();} else { if(param("option") eq 'login') { l_page(); } else { r_page(); } } foot();

Replies are listed 'Best First'.
Re: Using the param function
by ikegami (Patriarch) on Aug 15, 2009 at 15:45 UTC

    At the time of my posting, the parent node (in its entirety) consisted of the following:

    New to perl s_page(); if(param("option") == 'login') { l_page(); } else { r_page(); } foot(); problem is all 3 functions display forms and i want them to display one after the other not in the same page.


    You use the same trick you used two decide between the second and third to decide for all of them. A param decides which "page" to generate. A page controls which page will be visited next by including the param in the links and as a hidden field in forms.
Re: Using the param function
by chromatic (Archbishop) on Aug 16, 2009 at 01:07 UTC

    One problem is that you need to use the eq operator to compare string equality. The == operator compares numeric equality; both of the strings in your comparison likely numify to 0.

Re: Using the param function
by ikegami (Patriarch) on Aug 16, 2009 at 01:24 UTC
    Each request results in the script being executed from scratch, so getdo will always return zero. I suggested using a param, not a variable. Please head that advice.
Re: Using the param function
by jethro (Monsignor) on Aug 15, 2009 at 22:09 UTC
    Please use <code>-tags around your code (and <p>-tags around paragraphs). Your posting is nearly unreadable.