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

I'm trying to convert this script CGI.pm. Currently the script will allow a user to delete one file at a time, I would like to give the ability to delete multiple files at once. I have attempted to convert it to CGI.pm but am getting the dreaded error 500. Anyone have any suggestions? Thanks, lisaw
exit if $operate==0; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs=split(/&/,$buffer); foreach $pair (@pairs) { ($name, $value)=split(/=/,$pair); $value =~ tr/+/ /; $value=~s/%(..)/pack("c",hex($1))/ge; $f{$name}=$value; chomp($f{$name}); } print "Content-type:text/html\n\n$head $pageadmin $mid\n"; print " <table border=0 width=100% cellspacing=0 cellpadding=1>\n"; print "<tr><td bgcolor=#CCCCCC><b>&nbsp;File Removal System</b></td></ +tr></table>"; if(($f{'action'} eq "delete")&&(open(FILE,$f{'file'}))){ unlink($f{'file'})||print "<h1>Could Not Delete: ".$f{'file'}."</h +1>"; } $dir=$f{'dir'} if $f{'password'} eq $password; opendir(DIR,$dir); @dirfiles=readdir(DIR); closedir(DIR); @dirfiles=sort(@dirfiles); print "<p><center><table border=0 cellpadding=5 cellspacing=0><tr><td> +"; print "<p><center><table border=0><tr><form action=".$ENV{'REQUEST_URI +'}." method=post><td>\n"; print "<input type=hidden name=dir value=\"".$location."\" size=40>\n" +; print "<input type=hidden name=password value=orianphoto size=40></td> +\n"; print "<td rowspan=2><input type=submit value=\"Click Here To View Con +tents Of Directory\"></td></tr>\n"; print "<tr><td><input type=hidden name=password value=orianphoto size= +40></td></form></tr></table></center></p>\n\n"; print "</td></tr><tr><td>\n\n\n"; print "<p><center><table border=1><tr>\n"; print "<form action=".$ENV{'REQUEST_URI'}." method=post>\n"; print "<input type=hidden name=action value=delete>\n"; print "<td bgcolor=navy><font color=white><B>Files in The Photo Direct +ory: </td></tr><tr><td>\n"; $i=0; foreach $file(@dirfiles){ if((!opendir(TEST,$dir."/".$file))&&($f{'password'} eq $password)& +&($file ne ".")&&($file ne "..")){ $i++; print "<input type=checkbox name=file value=\"".$dir."/".$file +; if($i==1){ print "\" checked>"; }else{ print "\">"; } print $file."<BR>\n"; } } print "<input type=hidden name=dir value=\"".$location."\">\n"; print "<input type=hidden name=password value=orianphoto>\n"; print "<input type=submit value=\"Delete Selected File\"></td>\n"; print "</form></tr></table></center></p>"; print "</td></tr></table></center></p>\n"; print "$footer";

Replies are listed 'Best First'.
(jeffa) Re: Converting To CGI.PM
by jeffa (Bishop) on Jun 05, 2003 at 14:53 UTC

    When converting A to B, you had better know B first. If you don't understand CGI.pm now, you are going to have a very rough time converting something to it. Why not go over Ovid's Web Programming With Perl Course now, and then come back to this after you have a few CGI skills under you belt? Besides, CGI scripts that allow end-users to muck with the file system are loaded guns waiting to go off. ("You'll shoot your eye out!")

    In the meantime, here is a little CGI.pm script that i put together a while back that simply prints what params were sent to it. The part that prints the sent params is tricky ... i use the dreaded map statement in conjunction with CGI.pm's table methods -- those are probably the hardest methods in CGI.pm to learn, so don't sweat it if you don't get it. And please feel free to ask me questions. :)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Converting To CGI.PM
by LordWeber (Monk) on Jun 05, 2003 at 14:08 UTC
    Re: Converting To CGI.PM
    by DamnDirtyApe (Curate) on Jun 05, 2003 at 15:07 UTC
      Rather than convert all your HTML to CGI.pm, you may want to look at using the Template Toolkit (my favourite) or HTML::Template (also very popular) for the display portion of your script. This'll keep the processing and the presentation separate, and make your script much easier to write and maintain. Good luck!
      _______________
      DamnDirtyApe
      Those who know that they are profound strive for clarity. Those who
      would like to seem profound to the crowd strive for obscurity.
                  --Friedrich Nietzsche
    Re: Converting To CGI.PM
    by PodMaster (Abbot) on Jun 06, 2003 at 05:18 UTC