in reply to Print contents of a range of text files to browser (was: text files)

Assuming the files aren't delimited records and you just want to print them out line by line. You first open the directory, grab all the text files into an array.

opendir DIR, "./" or die "Can't open: $!"; my @files = grep { /\.txt\z/ } readdir DIR; closedir DIR;

Then print your header, loop over the array, open the text files, and print their results to the browser.

print "Content-type: text/html\n\n"; foreach my $file (@files) { open FILE, $file or die "Can't open file: $!"; while (<FILE>) { print $_; } }

That's a very basic way to do it. You'll probably also want to add in some formatting (exercise left to the reader :).

Update: Oops, I missed part of the question. You'll have to prompt for input, or accept the range of the text files first (do you want to do this via a form or the command line?). Then select only those files in the number range submitted.

Update 2: ++ to Screamer for pointing out the error below. I updated the example accordingly.

Replies are listed 'Best First'.
Re^2: Printing the Contents of Multiple Text Files from a Directory
by Aristotle (Chancellor) on Jun 16, 2002 at 19:47 UTC
    Careful. That should be grep { /\.txt\z/ } readdir DIR;
    Makeshifts last the longest.