I have been working on a small script for learning purposes and had a question about working with a array.
I am currently able to open a dir, read in the contents close the dir and foreach $_ array them and print $_ . I am using a small form hardcoded into the script that simply adds a checkbox next to each value in the array of files found. I then select which items/values I want to work with and submit the form.(it then opens a txt file and should place the selected values in it. Can someone please help me find my error, I am so close and always interested in learning more...
Thank you very much for your time~
Jim
#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); ######################## $path="/home/foo/www/dir"; $location="http://mysite.com/dir"; print "Content-type: text/html\n\n"; ######################## &Begin; sub top { opendir(DIR, "$path" ); @thefiles = sort(grep(/html$/, readdir(DIR))); $count = 0; foreach $_ ( sort @thefiles) { $count++; } closedir(DIR); print "<html>"; print "<head><title>MY SIMPLE FILE SELECTOR</title></head>"; print "<body bgcolor =\"#ffffff\" text =\"#000000\" link = \"#000000\" + vlink = \"#000000\" alink = \"#000000\">"; print "<center><h2>MY SIMPLE FILE SELECTOR</h2>"; print "<br><br><small><b>The following [$count] files were found in th +e [$path] Dir.</b></small><br><br>"; print "</center><table>"; } sub Begin { ⊤ print "<div align=\"center\"><center><table width=\"246\">"; print "<tr>"; print "<td align=\"left\" width=\"312\">"; print "<form action=\"http://mysite.com/cgi-bin/test.cgi\" method=\"PO +ST\">"; print "<li type=\"square\"><font size=\"2\"><i>Select files</i></font> +<BR>"; foreach $_(@thefiles) { $file_pathname = "$location" . "/" . "$_"; if (-e $file_pathname) {next;} $_ = "$FORM{'file'}"; print " <input type=\"checkbox\ +" name=\"$FORM{'file'}\" value=\"1\"><b>$_</b><br>"; } print "<p><input type=\"submit\" name=\"create_list\" value=\"Create\" +></p>"; print "</form>"; print "</td></tr></table></div><table>"; print "<br><A HREF=\"javascript:history.back()\">Go Back...</A></cente +r>"; ⊥ } sub bottom { print "</table><br>"; print "<small><small>$footer</small></small>"; print "</center></html>"; exit; } sub create_list { open(FILE, ">list.txt"); foreach $_ (@thefiles) { if ($_ == 1) { print FILE "$_\n"; } } close(FILE); &finished; } sub finished { print "<center><h3>Finished...</h3>"; print "You selected $_</center>"; }
In reply to a question about working with the forms and array by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |