David Gilden <mailto:[EMAIL PROTECTED]> wrote:
: --- what I have now----
:
: use CGI qw/:standard/;
: use CGI;
Why use CGI.pm twice? You need to read the CGI.pm docs. There
is no reason to ever call the module more than once.
: use Fcntl qw( :DEFAULT :flock );
: use CGI::Carp qw(fatalsToBrowser);
: use strict;
Also need to turn on warnings.
use warnings; # or use -w switch on older perl versions
: use switch;
CPAN has only Switch.pm, not switch.pm. Did you create your
own module or is this a typo?
: my $action = $q->param( "action" );
You have not yet defined $q as a CGI object. You should be
seeing this error in your browser.
: SWITCH: {
This does not follow the Switch.pm docs. It's basically a
named block which allows you to avoid writing 'else' clauses.
: if ($action =~ /Upload/) {
: last SWITCH;
: };
:
: if ($action =~ /Update/) {
: print redirect("./import_clean_csv.php");
: exit;
: last SWITCH;
Too late. You have already exit()ed the script.
: };
:
:
: if ($action =~ /Clean/) {
Indent the same way throughout the whole script. The previous
'if' blocks were indented four spaces. Why not do the same here?
: my @filesToRemove;
Whenever possible, declare your variables as you first use
them.
: chdir UPLOAD_DIR or die "Couldn't chdir to _data directory: $!";
UPLOAD_DIR has not been defined in this script. You should be
seeing this error in your browser.
: opendir(DR,"./");
How do you know it opened?
opendir DR, './' or die qq(Cannot open "./": $!);
: @filesToRemove = grep {$_ =~ /^(\w[\w.-]*)/} readdir DR;
my @filesToRemove = grep {$_ =~ /^(\w[\w.-]*)/} readdir DR;
: closedir DR;
:
:
: print $HTML_HEADER;
$HTML_HEADER is not defined in this script. You should be
seeing this error in your browser.
: print '<div align="center">';
:
:
: foreach my $fr (@filesToRemove) {
:
: print "Deleted $fr<br>\n";
: unlink($fr) or die "Couldn't Delete $fr $!";
: }
:
:
:
: print <<HTML_OUT;
: <p class="top-header">Your Done close this window!
: <form><input type="button" onclick="self.close()"
: value="Close Window"></form></p>
: </div>
: HTML_OUT
: print end_html;
:
: exit;
: last SWITCH;
Too late. You have already exit()ed the script.
: };
: }
:
:
: #more....
Other than typos and uninitialized variables, nothing above
seems to be hogging resources. The problem is likely in this
unseen part or in the switch.pm module (if that wasn't a typo.)
: __END__
How about skipping the Switch stuff and using something like this.
use CGI qw/:standard Button/;
.
.
.
if ( param() ) {
if ( param( 'action' ) =~ /Upload/ ) {
# call upload sub
} elsif ( param( 'action' ) =~ /Update/ ) {
print redirect("./import_clean_csv.php");
} elsif ( param( 'action' ) =~ /Clean/ ) {
print
header(),
start_html( -title => 'Clean Upload Directory' ),
div( { align => 'center' },
ul( { style => 'list-style-type: none;' },
li( clean_dir( 'upload_dir' ) ),
),
Button( { onclick => 'self.close()' },
'Close Window'
),
),
end_html();
}
} else {
# do other stuff
}
#more ...
sub clean_dir {
# Not Tested
# Don't output anything to the browser from this subroutine.
# Return an array reference containing the report. Allow the
# caller to decide how it will be marked up.
my $upload_dir = shift;
chdir $upload_dir or die qq(Couldn't chdir to "$upload_dir": $!);
opendir my $dir, './' or die qq(Cannot open "./": $!);
my @filesToRemove = grep {$_ =~ /^(\w[\w.-]*)/} readdir $dir;
closedir $dir;
my @report;
foreach my $file ( @filesToRemove ) {
if ( unlink $file ) {
push @report, qq(Deleted "$file");
} else {
push @report, qq(Could not delete "$file": $!);
}
}
return [EMAIL PROTECTED];
}
__END__
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>