Directory file listing like dos "DIR *.html" clone

Hi,
   I need to scan a directory (via CGI) to have all html files (the names) into an array (like dir *.html in DOS).
I've writed this piece of code but it seems not work.
Any idea?

#!/usr/bin/perl
open(STDERR,'>&STDOUT');
$| = 1;
print "Content-type: text/html\n\n";
& scan_files;

sub  scan_files {

my (@files,$list);

#$dir will change by a data sent via cgi
$dir="/inetpub/wwwroot/gabbia/cgi-bin/Annunci/male_slave";

opendir(dir,$dir);
@files=grep { /^\./ && -f "$dir/$_"} readdir(dir);
closedir (dir);
foreach $list (@files)
{
print $list;
print "\n";
}
}

#I'd like have the names into @files array
zuppyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MindoCommented:
The source code is:
=======================================
#!/usr/local/bin/perl -w
 
open(STDERR,'>&STDOUT');
$| = 1;
print "Content-type: text/html\n\n";

&scan_files;

sub scan_files
{
  $dir=".";

  my(@files);
 
  opendir(DIR, $dir);
  while(defined ($file = readdir(DIR)))
  {
    if((-f $file)&&($file =~ /.*\.html$/))
    {
      push(@files, $file);
    }
  }
  closedir (DIR);
 
  foreach $file(@files)
  {
    print "$file\n";
  }
}
=======================================

It finds all the *.html files in your directory (. - current directory), puts them into the @files array and then prints them.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zuppyAuthor Commented:
I've founded error...but your solution runs nice too...
So for you 30 points :)
0
zuppyAuthor Commented:
but please replay...so I can give them
0
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

MindoCommented:
Huh? You wrote please replay. What to replay, eh? :-)
0
zuppyAuthor Commented:
sorry, it was a "broswer reload" problem :)
Have you taken your points?
0
MindoCommented:
Yeah, of course, thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.