Thanks for the various replies. Below is my initial crap code.
Its simply a cgi that when accessed via the web shows the contents of
"bla.txt" on a page inset in a form textarea, which when
modified/resubmitted, is updated.
The " page display" and "form edit" fills the same functionality, which I
guess is unlike what is typically done on the web, whereby separate edit
and display pages usually exist.
Only problem is when reloading or accessing the page, without form
parameters when otherwise hitting submit, a whitespace is insterted before
each line of the textarea. It occurs after alternating reload and edit
actions, with an effect such as for example:
<textarea>
Line 1
Line 2
Line3
</textarea>
I guess it has something to do with how "my @lines" is read into the
textarea. Can anyone enlighten me on the exact cause and solution?
I only use CGI.pm as its such a small script. No non-standard modules.
-------- start of crap code ------------
use CGI qw
standard);
print header;
$mytext = param('mytext');
$myfile = "bla.txt";
open (BLA,$myfile);
my @lines = <BLA>;
close(BLA);
print start_form, 'notes',br,
textarea('mytext',"@lines"),br,
submit, end_form;
# If script is accessed without submit action, i.e.: direct URL
# access/reload of page, do not write to file.
# This is detected by the empty form parameter (a better way must exist!?).
# Otherwise, write whatever input was entered (or pre-entered) in textarea
# into bla.txt.
if ($mytext ne ""){
open(BLA, ">$myfile");
print BLA $mytext;
close(BLA);
}
------------ end of crap code ------------
Any quick tips how to improve, expand and correct otherwise crap code
would be much appreciated.
The purpose is simply a quick notes utility for myself, but possibly also
to be used by more than one person, in which case file locking would
somehow need to be added to prevent overwriting simultaneous edit actions.