I am trying to make a perl script that will open a CSS file add the CSS script into a textarea for editing then after hitting submit on the form save it back to the CSS file
as easy as this should be I keep running into problems getting it to work.
#!/usr/bin/perl
BEGIN {
use CGI::Carp qw(carpout confess);
open(LOG, ">>","Entrance.log") or
die("Unable to open mycgi-log: $!\n");
carpout(LOG);
}
#$SIG{__DIE__};
#$SIG{__WARN__};
use CGI qw(:standard);
use strict;
my $RoomName = 'Entrance';
my $CSS_Name = qq{$RoomName.css};
if (param('cssScript')) {
write_file($CSS_Name, param('cssScript'));
}
my @CSS_Array = read_file($CSS_Name);
my $CSS_script = join("\n", @CSS_Array);
print header;
print start_html("$RoomName Edit"),
h1("$RoomName CSS"),
start_form;
print textarea(-name=>'cssScript',
-default=>$CSS_script,
-rows=>50,
-columns=>75);
print p,
submit,
end_form,
hr;
print end_html;
sub read_file
{
my ( $f ) = @_;
open F, "< $f" or die "Can't open $f : $!";
my @f = <F>;
close F;
return wantarray ? @f : \@f;
}
sub write_file
{
my ( $f, @data ) = @_;
@data = () unless @data;
open F, "> $f" or die "Can't open $f : $!";
print F @data;
close F;
}
Any Ideas what I am doing wrong?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.