in reply to Don't blindly recommend code
Ignoring the "local", notice the typo in the tr///;
Here's an interesting attempt to check for a valid email address:sub ucase { local($s1) = @_; $s1 =~ tr/[a-z]/[A-Z}/; return $s1; }
Mindboggling formatting (quick, where does the "if" end):$chk =~ /(.*@.*\.[a-zA-Z]{2,3}$)/ && $chk !~ /(^\.)|(\.$)|( )|(\.\.)|( +@\.)|(\.@)|(@.*@)/
Regarding the above code snippet, I won't post the &showErr sub because he has lines of HTML over 600 characters long!!!sub readem { local $insFile = shift; local $back = ""; if (open(FL, "<$insFile")) { while (<FL>) {$back .= $_;} close(FL); } else {&showErr('Fatal File Read Error');} return $back; }
Hmmm... I wonder how he parses form data (incidentally, he reproduces the following code in many different files. If he tries to fix any of the bugs, he's got many different places to fix it in):
In the above snippet, he reproduced every error I pointed out in use CGI or die; and even came up with some new ones. I tried to find an email address for this person, but gave up -- though I would admit that I didn't try hard. Is it appropriate to email someone to tell them how many problems they have with their code?@pairs = split(/&/, $query_string); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $name =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/~!/ ~!/g; $name =~ s/~!/ ~!/g; $value =~ s/<([^>]|\n)*>//g if $name ne "comtext" && $name ne +"ONld" && $name ne "edstext" && $name ne "mtxt"; $name =~ s/<!--#(.|\n)*-->//g; $value =~ s/<!--#(.|\n)*-->//g; $value =~ s/("|')//g if $name ne "comtext" && $name ne "ONld" +&& $name ne "edstext" && $name ne "mtxt"; $value =~ s/(`|\0|\\[^\\n])//g; $name =~ s/(`|\0|\\)//g; $FORM{$name} = $value; }
Okay, I'll stop now. I think the point is made :)
Cheers,
Ovid
Update: Ooh, ooh, stop me before I kill again! Here's another beauty:
Okay, so he's using "windowing" on the year. That's pretty bad, but here's how he calls it:sub date_time { my($s1) = @_; my($mon,$year); ($mon,$year) = (gmtime($s1))[4,5]; $mon++; if ($year < 39) { $year = "20$year" } elsif ($year > 99 && $year < 2000) { $year = 2000 + ( $year - 100 +) } elsif ($year > 38) { $year = "19$year" } return ($mon,$year); }
Code like this makes me not feel so bad about my Perl limitations :)$datetime = &date_time(&date_time(0));
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (Ovid) Re: Don't blindly recommend code
by davorg (Chancellor) on Mar 26, 2001 at 19:04 UTC | |
|
Re: (Ovid) Re: Don't blindly recommend code
by chromatic (Archbishop) on Mar 26, 2001 at 22:43 UTC |