OK, here are some general pointers:
- use CGI qw(:param) to process your form data; handrolled stuff is messy, hard to maintain, and insecure. See use CGI or die; for more about why.
- use strict always and run under -w, the latter especially when you're developing. Perl will catch all sorts of errors you won't. As things stand, your script could fail for lots of reasons in lots of places and you'd never know why.
our own Ovid has written a CGI tutorial guide, check his homenode for the link (follow the link in this paragraph)
Now, some specifics:
What your ifs are doing is done more maintainably with a hash. I like to do this at the top of complex scripts:
my %actions = (
option1 => \&process_option1,
option2=>\&processoption2
);
my $option = param('option');
$action{$option}->() or default_action();
exit;
And so forth. That nasty-looking \& thing creates references to subroutines, which are called by
the $action{$option} line. Here, what you should do is create a hash whose keys are as you have them, and whose values
are the files that each kind of action works on:
my %file_hash = (
a=>'notiagro.html',
d=>'notideportes.html'
# and so on
);
my $catfile = $file_hash{$cat} || 'default value';
I know that doesn't get you everything you need. You have a start on the harder parts, but get this part working first and then come back to those.
For finding the link to extract and replace, you need to think about
how your file looks. I can't help you with that with the information I have now,
but I've gone on long enough so far. Hope this gets you over a hurdle or two.
Philosophy can be made out of anything. Or less -- Jerry A. Fodor |