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:#!/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;
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. ;)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;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |