Dear Perl Gurus,

I have some  problems that I think are a result of how my Switch statement is 
written. 
This script is invoked via a web browser to upload a file, and do a few other 
things. 
However it appears that the user system / network, or my script is stalling. So
the user clicks the button  a second and a third time before the script has
finished. The system admin has made me aware that this script is maxing out the
CPU usage of server. He is not happy....


I thought have surrounding a portion of the code and putting in an if 
block ...

if (!$state) {

do lots of stuff related to file upload...
}    

$state could be read and written to and store a 0 for ready to do something, 
or a 1 for, 'busy now, don't brother me'......


Another issue to improve the performance of the script
was to move stuff inside a switch block, but I am not sure how this would 
impact scope : 

SWITCH: {
    
    if  ($action =~ /Upload/) {
      

use Fcntl qw( :DEFAULT :flock );
use constant MAX_FILE_SIZE  => 2 * 1_048_576;   # Limit each upload to 2 MB
use constant MAX_DIR_SIZE   => 10 * 1_048_576; # Limit total uploads to 10 MB
use constant MAX_OPEN_TRIES => 100;
  last SWITCH;    
    };

--

    if  ($action =~ /AnotherCmd/) {
### is order backwards on these next two lines?
        exit;
        last SWITCH; 
}


Could some comment on using Switch or Case statements vers If {} else blocks

Thanks...
Dave Gilden
PS: I am not sure of syntax that I should be using for Switch I have seen 
several variants 
as I have read documentation today....


--- what I have now----

use CGI qw/:standard/;
use CGI;
use Fcntl qw( :DEFAULT :flock );
use CGI::Carp qw(fatalsToBrowser);
use strict;
use switch; 


my $action = $q->param( "action" );

SWITCH: {
    
    if  ($action =~ /Upload/) {
        last SWITCH;    
    };
    
    if  ($action =~ /Update/) {
        print redirect("./import_clean_csv.php");
        exit;
        last SWITCH;    

    };
        
        
    if  ($action =~ /Clean/) {
    my @filesToRemove;  
     
    chdir UPLOAD_DIR or die "Couldn't chdir to _data directory: $!";
    
    opendir(DR,"./");
    @filesToRemove  =  grep  {$_ =~ /^(\w[\w.-]*)/} readdir DR;
    closedir DR;


print $HTML_HEADER;
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; 
    };
}


#more....

__END__


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to