We need to get you into the habit of using arrays to cut back on redundant code. The following stipped-down version of your code demonstrates how easy it really is to write maintainable code. I have left out the mail part completely, and i am only using textboxes - putting the text areas, and select boxes back in is your homework assignment. Hope this gets the lightbulb burning bright in your head. ;)
#!/usr/bin/perl -T use strict; use warnings; use CGI qw(:standard); my @name = qw( author distributor copyright abstract keywords description distribution robots language rating ); print header, start_html('Meta Tag Generator'), start_form, table( # i know maps are scarey, just think of this as a # backwards for loop (read bottom up) map { Tr( td(ucfirst $_ . ': '), td(textfield(-name=>$_,-size=>40)), ) } @name ), submit('submit'), end_form, ; if (param('submit')) { for (@name) { # this is how you trim down fetching params code ;) my $param = param($_); # this skips empty fields, you might want to err instead next unless $param; # notice the use of meta() as well as escapeHTML() # since we have alread loaded CGI.pm, let's use it! print escapeHTML(meta{name=>$_,content=>$param}),br; } } print end_html;
So, how would i go about adding specifics to the items, such as using a text area for description and a drop down box for language? For the former i would use a config hash, one that knows which form element to use ... well, a picture is worth a thousand words ... so ponder on this after you master the code above:
my @dist = qw(local global); my @robo = qw(index noindex follow nofollow); my @lang = qw(EN EN-GB EN-US ES ES-ES FR IT JA KO DE­); my @rate = qw(kids general mature restricted); my %name = ( author => [ sub{textfield(@_)} , {-size=>40} ], distributor => [ sub{textfield(@_)} , {-size=>40} ], copyright => [ sub{textfield(@_)} , {-size=>40} ], abstract => [ sub{textfield(@_)} , {-size=>40} ], keywords => [ sub{textarea(@_)} , {-rows=>5,-columns=>30} ], description => [ sub{textfield(@_)} , {-rows=>5,-columns=>30} ], distribution => [ sub{popup_menu(@_)} , {-values=>['',@dist]} ], robots => [ sub{popup_menu(@_)} , {-values=>['',@robo]} ], language => [ sub{popup_menu(@_)} , {-values=>['',@lang]} ], rating => [ sub{popup_menu(@_)} , {-values=>['',@rate]} ], ); print header, start_html('Meta Tag Generator'), start_form, table( map { Tr( td(ucfirst $_ . ': '), td $name{$_}[0]->( -name=>$_, %{$name{$_}[1]} ) ) } keys %name ), submit('submit'), end_form, ; if (param('submit')) { for (keys %name) { my $param = param($_); next unless $param; print escapeHTML(meta{name=>$_,content=>$param}),br; } } print end_html;
The idea is to give each key a datastructure that contains an anonymous subroutine to execute and some arguments to pass to that subroutine. It is complex, but it is also terse and easy to maintain. But of course, now that @name is %name (a hash), the order is not preserved. There are vays to fix zis, but i'll let you try to figure out how as an exercise. ;)

Good luck. :)

Update: ahhh, indeed it is Aristotle. Thanks for watching my back once again. ;) sulfericacid ... do what Aristotle did, there is no need to be needlessly complex.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Meta Tag Generator by jeffa
in thread Meta Tag Generator by sulfericacid

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.