Well, this might be going out on a limb, but . . .
Sounds like a job for polymorphism!!!

Here's the scenario - you have a group of objects, each derive from a common parent (default). Each objects overrides a method called handle - which will take care of the task at hand.

Here is code for the Default class:

package Default; use strict; sub new { my $class = shift; my $self = { }; return bless $self, $class; } sub handle { my ($class, $text) = @_; return $text; } 1;
All it does is contain an empty hash, and a method called handle which simply returns what it was handed.
Here are two classes that will derive from Default:
package Upper; use strict; use Default; use vars qw(@ISA); @ISA = qw(Default); sub handle { my ($class, $text) = @_; return uc($text); } 1; ################################ package Lower; use strict; use Default; use vars qw(@ISA); @ISA = qw(Default); sub handle { my ($class, $text) = @_; return lc($text); } 1;
And finally, the test script. It is a very simple and generic test to show the flexibility in using polymorphism.
#!/usr/bin/perl -w use strict; use Default; use Upper; use Lower; my $arg = shift || ''; my %handlers = ( default => Default->new, upper => Upper->new, lower => Lower->new, ); my $ref = $handlers{$arg} || $handlers{'default'}; print $ref->handle("AaAaAaAa"), "\n";
The hash is used to map command line arguments to the class to use - your problem might map the name of a web page to the class to use. If the argument is not including among the handlers, then the default handler is used. This will allow you to make new handlers (which print out the appropriate HTML page).

If you want to try this out, put each of the 3 classes in their own file (with .pm extension), and copy the test script to an executable file in the same directory. Run the test script with

Hope this helps, at least I hope it gives you insight into ways to solve your problem.

Jeff

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

In reply to (jeffa) Re: CGI coding style by jeffa
in thread CGI coding style by 2501

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.