http://www.perlmonks.org?node_id=671076

ikkon has asked for the wisdom of the Perl Monks concerning the following question:

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?