Couldn't resist posting some of the more amusing code samples from this particular guestbook.

Ignoring the "local", notice the typo in the tr///;

sub ucase { local($s1) = @_; $s1 =~ tr/[a-z]/[A-Z}/; return $s1; }
Here's an interesting attempt to check for a valid email address:
$chk =~ /(.*@.*\.[a-zA-Z]{2,3}$)/ && $chk !~ /(^\.)|(\.$)|( )|(\.\.)|( +@\.)|(\.@)|(@.*@)/
Mindboggling formatting (quick, where does the "if" end):
sub readem { local $insFile = shift; local $back = ""; if (open(FL, "<$insFile")) { while (<FL>) {$back .= $_;} close(FL); } else {&showErr('Fatal File Read Error');} return $back; }
Regarding the above code snippet, I won't post the &showErr sub because he has lines of HTML over 600 characters long!!!

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):

@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; }
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?

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:

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); }
Okay, so he's using "windowing" on the year. That's pretty bad, but here's how he calls it:
$datetime = &date_time(&date_time(0));
Code like this makes me not feel so bad about my Perl limitations :)

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid) Re: Don't blindly recommend code by Ovid
in thread Don't blindly recommend code by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.