in reply to Peruse my code...
Well, now all input is checked, but there are caveats about these checks. If some input fields are not given, you'll get warnings for undefined values. Also some Regexps are broken or inefficient. All in all, i'd write it like this:
--#!/usr/bin/perl -T use strict; use warnings; use CGI; my $w = new CGI; my $ip = $ENV{REMOTE_ADDR} || 'N/A'; my @errors = (); my $file = time.int rand 1_000_000; my %spec = ( username => qr#^[A-Za-z][-.\w]{2,29}$#, domain => qr#^(a|c|f|h|ho|i|k|o|s|x)\.com$#, email => qr#^[\w\.\-]+\@(?:[a-z\d\-]+\.)+[a-z\d]+$#i, service => qr#^Yes|No$#, conditions => qr#^Yes$#, ); my %fields; foreach( keys %spec ){ my $v = $w->param($_) or do { push @errors => "$_ not defined"; next }; $v =~ $spec{$_} or do { push @errors => "$_ invalid input"; next }; $fields{$_}=$v } print_error( @errors ) if @errors; open LOGFILE,'>>',"var/log/accounts/$file" or die "$file opening failed: $!"; print LOGFILE join(',',@fields{qw/username domain email service/},$ip) +,"\n"; close LOGFILE; print $w->header('text/plain'), "done"; sub print_error { print $w->header('text/plain'), @_; exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Peruse my code...
by Arien (Pilgrim) on Aug 31, 2002 at 17:33 UTC | |
by fruiture (Curate) on Sep 01, 2002 at 09:48 UTC |