On Apr 14, 2005, at 2:09 PM, Charles K. Clarkson wrote:

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__


Or look at one of the several different modules designed to simplify the process of creating a multipage script like CGI::Application, CGI::Builder, or CGI::FormBuilder (somewhat).


Sean


-- 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