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'

In reply to Re: How to perform recursion in any OS? by shmem
in thread How to perform recursion in any OS? by rollec

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.