Ok, what I am going to show you may freak you out. But that's ok.

This is not meant to overwhelm you. I hope this is more of an inspiration of what perl can really do for you

What you are learning is very useful. I've gone through those motions like most of us here have. But also, you should have a hint of what's at the end of the rainbow..

So.. here. I wrote this just for you. I'll come back later and explain a little more. This code is fully tested and functional.

package CGI::Application::Tutorial::Namegame; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::Feedback ':all'; use CGI::Application::Plugin::AutoRunmode; use CGI::Application::Plugin::Forward; use strict; use warnings; use Carp; sub setup { my $self = shift; $self->start_mode('choose_name'); } sub choose_name : Runmode { my $self = shift; $self->_detect_name_change_request; my $q = $self->query; my $html = $q->start_html . $self->_nav . $q->h1('Choose Name') . $q->start_form . $q->textfield('name') . $q->submit('save') . $q->end_form . $q->end_html; return $html; } sub show_verse : Runmode { my $self = shift; $self->_detect_name_change_request; my $name = $self->_get_name_chosen or return $self->forward('choose_name'); require Lingua::EN::Namegame; my $verse = Lingua::EN::Namegame::name2verse($name) or $self->feedback("Sorry, cannot generate verse for [$name]") and $self->session->clear('name') and return $self->forward('choose_name'); my $q = $self->query; my $html = $q->start_html . $self->_nav . $q->h1('Your Verse:') . $q->pre($verse) . $q->end_html; return $html; } sub _detect_name_change_request { my $self = shift; my $name = $self->query->param('name'); defined $name or return 0; $name=~/^\w+$/ or $self->feedback('Your "name" input sucks.') and $self->feedback('Try again.') and return 0; $self->session->param( name => $name ); $self->session->flush; $self->feedback("Ok, name choice saved for [$name]."); return 1; } sub _get_name_chosen { my $self = shift; my $name = $self->session->param('name'); defined $name or $self->feedback('no name chosen yet') and return; return $name; } sub _nav { my $self = shift; my $navetc = $self->query->p(q{<a href="?rm=choose_name">Choose Name</a>}) . $self->query->p(q{<a href="?rm=show_verse">Show Verse</a>}) . $self->get_feedback_html; return $navetc; } 1;

here you can see what it does in action


In reply to Re^3: How to retrive value from session using Perl CGI. by leocharre
in thread How to retrive value from session using Perl CGI. by ramesh_ps1

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.