in reply to Re: files
in thread Read and Combine Range of Two Files (was files)

What if you would have the files been selected from a select menu. Like one dropdown with one file name and another with the other file name using a form to submit the information and display results to the browser window?

Replies are listed 'Best First'.
Re: Re: Re: files
by SarahM (Monk) on Jun 14, 2002 at 20:21 UTC
    That is different, but it isn't too hard...first, you need to use CGI.pm, then you get a list of the files, open them and write them out to another file. Here is an example...your webform will need one input named 'outfile' for the file you want to save to. You will also need a series of inputs named 'fileX' where 'X' is a number, one for each input file.

    WARNING!!! This example doesn't use taint in order to make it more readable. In a real script you should always use taint.

    use CGI; my $q = new CGI; # Get a CGI object open (OUT, ">$q->param('outfile')") || die $!; # Open our output file my @files = grep{/^file\d+$/} $q->param(); # Grab a list of params for my $filename (@files){ open (IN, $q->param($filename)) || die $!; # Open each input file print OUT <IN>; # Print the input file to the output file close (IN); # Make sure you close the input file } close (OUT);
      Ok. But the interface for this program has two select menus that read the directory where the files are stored and they're dynamically populated on each select menu. From there one choice of file is made from one of the select menu and other from the other select menu, by clicking on the submit bottom the code behind will process the range of the files selected and it will get displayed to the browser. Thank you so far, sorry if I am driving you crazy with this. Just want to get this clear as possible.