Greetings,

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 { &top; 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 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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>"; &bottom; } 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.