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?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.