I'm so very tired and I'd like an answer right away... Yes, I know, how selfish of me, and I'm new here, to boot. Anyway, I'm trying to role my own Wiki and it's been pretty fun. The only problem, however weird (I try to cover all bases) is that if the user submits a page containing one zero (0, no quotes, no parens) or nothing at all, the database just spits out another edit page, as if nothing was submitted at all. How can I make Perl realize the difference between undefined and a 0 and a blank? Yes, I use warnings and strict religiously... But as you can see, the code is getting pretty nasty, as I've tried to "force the zero" many a way...
#!/usr/local/bin/perl -w use diagnostics; use strict; use CGI; use HTML::Entities; #anomolie. no blank pages, no zeroes, ask the perl gods. my $c = new CGI; dbmopen(my %WIKI, "wiki", 0644); my(@p, $p, $q, $error); @p = $c->param; $p = (defined $p[0] and $p[0] eq "keywords" ? $c->param("keywords") : +$p[0]) || "WelcomePage"; $error = ($p !~ /^(search|edit)?([A-Z][a-z]+([A-Z][a-z]+)+)/ ? "Invali +dAction" : ""); $q = $p; $q =~ s/^[a-z]+(.*)/$1/; $WIKI{"$q"} = scalar(encode_entities($c->param($p))) if $p =~ /^edit/ +and defined(scalar($c->param($p))) and !($error); $WIKI{"$q"} =~ s/\&\#13\;//g if $WIKI{"$q"}; $p = $q if $p =~ /^edit/ and $c->param($p); print "Content-Type: text/html; charset=UTF-8\n\n", $c->start_html(-ti +tle=>$p), $c->h1($c->a({-href=>"/wiki/"},"HtmlismOpenWiki")." : ".($p + =~ /^edit/ ? $c->a({-href=>"?$q"},$p) : ($p =~ /^search/ ? $c->a({-h +ref=>"?$q"},$p) : $c->a({-href=>"?search$q"},$p)))); if ($p =~ /^edit.*/ and not $error and not $c->param($p)) { print $c->startform("post","/wiki/"), $c->textarea({-style=>"width:100%;height:3in",-name=>"$p",-default +=>($WIKI{$q} ? $WIKI{$q} : "")}), $c->p($c->submit), $c->endform } print wikimake(($error ? $c->p($error) : "")), wikimake(($WIKI{$q} && +($p =~ /^[A-Z]/ or $c->param($p)) ? $c->p($WIKI{$q}) : "")), ((($p =~ + /^[A-Z]/ or $c->param($p)) and !$error) ? ($c->hr.$c->p($c->a({-href +=>"?edit$q"},"Edit this page"))) : ""), $c->end_html; dbmclose(%WIKI); sub wikimake { my $z = shift; $z =~ s/\b([A-Z][a-z]+([A-Z][a-z]+)+)/$c->a({-href=>"?$1"},$1)/eg; $z =~ s/\n/$c->br/eg; return $z; }

In reply to Vanishing Data by Anonymous Monk

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.