in reply to a question about working with the forms and array
There's a lot to tackle here. First, and most important, is that you don't tell us what, precisely, isn't working. That would potentially help to narrow it down, because there are a lot of problem areas.
The latter two are really serious problems: you have no way of reading the results of your user's interaction.
- Was your opendir call in your Begin subroutine successful? If it wasn't, you wouldn't know, because it would fail silently.
- Solution: don't let it fail silently. Rewrite that line as opendir DIR, $path or die "Can't open directory:$!\n";
- Where are you reading the form input values from?
- Solution : standard practice is to use CGI and import the param function to read the request parameters. You do this by putting use CGI 'param'; or use CGI qw(param); near the top of your script, and calling param('foo') to get the submitted value.
- Where is the %FORM hash populated? If it's not populated, then all the parameter names in your HTML form will be blank. (obviously this relates to the issue above).
- Solution : make sure it's populated. Debugging this sort of issue is easier if you run your script with use warnings; or -w in your hash-bang line. This would cause perl to warn you that you're using uninitialized values.
Some larger issues that pertain to performance and readability: foreach (@thefiles) and foreach $_ (@thefiles) are functionally equivalent, but the longer version has the added bonus of not being idiomatic and also potentially confusing. You don't need to loop through an array to get its size, and you definitely don't need to sort that array and throw away the results while doing so. $count = @thefiles will get you the answer you seek there.
Most importantly, you're not using strict in this code, which gives you the false convenience of globals; this makes it harder to understand your program, especially for someone who didn't write it. This has a further deleterious effect on your subroutines, which don't group the various functional bits of your program together in a natural way. Think about the smallest pieces of stuff your program needs to do and work from there. I would suggest that you have one subroutine that gets the list of files, sorts it, and returns it, and another to generate the checkbox form, and takes as a parameter the list of files. That should be enough to get you started.
If not P, what? Q maybe?