I am writing a simple text editing routine for use in a web app. What I want to do in the following code is print the textfile to screen if the textfile exists otherwise, enter some text and save it off to the file - so when I hit submit, the data saves and displays. This works fine. If the text is empty, I don't want it to save - this is where Im having some issues - When I hit submit and have nothing entered in the bottom textarea, it still updates the top textarea ive tried things like
if (defined(param('SERVER_NOTES')) =~ m/\w+/ )
and
if (! defined(param('SERVER_NOTES)) !~ m/\W+/ )
amongst several others...

any hints would be appreciated
#!/usr/bin/perl -T use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); use Data::Dumper; #$CGI::POST_MAX=1024 * 100; # max 100K posts #$CGI::DISABLE_UPLOADS = 1; # no uploads # Clean up our UNIX environment # for more infor read perldoc perlsec $ENV{'PATH'} = '/bin:/usr/bin'; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; $|++; my @text; if ( defined (param('NOTES')) =~ m/\w+/ ) { @text=param('NOTES'); open (SERVER_NOTES, ">/var/www/cgi-bin/notes") or die("Unable to open notes: $!\n"); for my $text(@text) { print SERVER_NOTES "$text\n"; } close (SERVER_NOTES); } ## Start HTML ## print header; print start_html(-title=>"AWI Printer Administration - printer notes", -BGCOLOR=>"#cccc99" ), "\n"; print "<tt><center>\n"; print h3("AWI", "Printer", "Administration"),"\n"; print "</center>\n"; print hr,"\n"; # End header print br,br; if ( -s "/var/www/cgi-bin/notes" ) { print Delete_all(); open FH, "/var/www/cgi-bin/notes" or die("unable to open notes: $!\n"); my @new_text=<FH>; print "<center>\n"; print textarea('SAID',"@new_text", 15, 80, 0), "\n", br, br; print "</center>\n", br; #for (@text) { print }; } print br,br,br; print start_form; print "\n<center>\n"; print h3("Change printer notes"); print textarea('NOTES',"", 15, 80), "\n",br; print submit('Submit'); print "</center>\n",br; print Dumper @text; print end_html;

Thanks
Ted
--
"Men have become the tools of their tools."
  --Henry David Thoreau

In reply to Simple CGI text editing by tcf03

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.