Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I have a html interface of sorts that allows users to add their email address and phone numbers for sms alerts. Additionally, there is a tick box that allows them to turn on and off their alerts. They were susposed to seperate the email addresses, if there were more than 1, with a comma.
i.e. fred@myserver.com,joe@myserver.com
This all worked fine until someone entered 2 addresses on two lines, ie,
fred@myserver.com
joe@myserver.com
Then the whole thing got out of whack. Does anyone have a better way of doing this to ensure the data can't be screwed up?
while (<SERVICES>) { chop; print FH "$_\n"; $temp = $c->param("e$."); if ($temp eq "e$.") { print FH "email 1\n"; } else { print FH "email 0\n"; } $temp = $c->param("el$."); #chomp($temp); $temp =~ s/\n//g; $temp =~ s/\r//g; print FH "$temp\n"; $temp = $c->param("s$."); if ($temp eq "s$.") { print FH "sms 1\n"; } else { print FH "sms 0\n"; } $temp = $c->param("sl$."); $temp =~ s/\n//g; $temp =~ s/\r//g; print FH "$temp\n"; }

Replies are listed 'Best First'.
Re: writing a config file from a html form
by merlyn (Sage) on Feb 25, 2007 at 21:20 UTC
    You do have some sort of round-trip verification with blacklist, right? as in, you send a message with a secret to the indicated address, and they need to confirm that address back with you. Failure to confirm within X hours means the address goes on to a blacklist, never to be valid again.

    Otherwise, what you've created is a system that people can use to abuse other people, with no hope of tracing things back. Please don't do that... it's not being a good net neighbor.

      Yes. This is for an internal alert system at work. You need a username/password to get to this page, and it will only send emails internally. I'm not into the spamming business :-)
Re: writing a config file from a html form
by rodion (Chaplain) on Feb 25, 2007 at 23:16 UTC
    I'm having a little trouble telling what's going on from the code you posted. I don't know the purpose of "FH", "SERVICES" or "$c", but I'm guessing that this bit of code is for updating your config file. The use of "$.", the input line number, as part of a hash key makes me think you might be storing or updating information in the config file based on line number, and that could be a source of your problem. If my guess is right, and your rolling your own config file updates this way, I suggest looking at CPAN:Config::Simple. Scroll down to the headings on "SAVING/WRITING CONFIGURATION FILES", "CREATING CONFIGURATION FILES" and "MULTIPLE VALUES" and I think you might find that the package does just what you want. Good luck with your project.