
December 20th, 2012, 03:26 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 1
Time spent in forums: 8 m 49 sec
Reputation Power: 0
|
|
|
List files in a directory into array and print
I would like to list all *.rpt files in a directory into an array and then convert each file name into a link. The $rpts parameter is sourced from an html page with three links: Billing, GL, Inventory. I have presented test code here for review. When you replace $rpts with, say, 'billing', one would expect a list of files to display but nothing happens -?! Any help would be greatly appreciated!
#!/usr/bin/perl
#use strict;
use CGI qw(:standard);
#Three types of web reports: Billing, GL, Inventory
#my $rpts = param('reports');
my $dir = "/production/reports/$rpts";
opendir(DIR, $dir);
while (my @file = readdir(DIR)) {
# We only want files
next unless (-f "$dir/@file");
# Use a regular expression to find files ending in .rpt
next unless (@file =~ m/\.rpt$/);
print "$file(@file)\n";
}
closedir(DIR);
exit 0;
|