Never use backticks or qx() without taint mode in a program driven from the web. See perlsec.
To make your program portable, use the builtins opendir and readdir to read directories. Use File::Spec to assemble paths from directory and file. Here's a quick diff with the changes.
--- 1177457.pl 2016-12-08 12:36:42.215747438 +0100
+++ 1177457.pl.new 2016-12-08 12:45:35.603768833 +0100
@@ -2,7 +2,7 @@
use strict;
use warnings;
-
+use File::Spec;
### This program looks at the current directory and then makes a path
+ to all the sub directories.
@@ -22,17 +22,20 @@
sub list {
my $path=$_[0];
#print "DEBUG - listing [$path]\n";
- chomp(my @files = `ls -a $path`);
+ my @files = do {
+ opendir my $dh, $path or die "opendir '$path': $!\n";
+ grep !/^\.\.?$/, readdir $dh;
+ };
my @dirs;
foreach(@files) {
- if (-d "$path/$_" && $_ ne "." && $_ ne ".."){
- push (@dirs , "$path/$_");
- }
+ my $f = File::Spec->catpath($path,$_);
+ push @dirs, $f if -d $f;
}
print "-------------------------------------\n";
print "Generating HTML doc for path = [$path]\n";
- open(FHOUT, ">", "$path/index.html")
- or die "Can't open '$path/index.html':$!\n";
+ my $index = File::Spec->catpath($path,'index.html');
+ open(FHOUT, ">", $index)
+ or die "Can't open '$index':$!\n";
print FHOUT "<!DOCTYPE html>";
print FHOUT "<html><head>"
. "<title>listing:</title>"
I didn't tidy the program, you have to do that yourself. There's no call to list() except in that loop whith an empty my() array -
foreach (my @dirs) {
&list($_);
}
- so it doesn't produce any output but warnings (print() on unopened filehandle FHOUT).
Omit the ampersand from the call to list(). Look it up in perlsub to see what it does.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
|