I'm making a program that allows a user to generate a HTML page of directories in a system. My issue is that I only made the code to work for linux. I need it to work for ALL operating systems. How can I do this?

#!/usr/bin/perl use strict; use warnings; ### This program looks at the current directory and then makes a path +to all the sub directories. ### Step 1: Create a subroutine with Variables for the program. This i +ncludes the following: ### Files, Path and Directories. ### Step 2: make the program list the files and folders of current dir +ectory. Push folders into an array ### Step 3: Print Dirs ### Step 4: Recurse if (@ARGV != 1) { print "Usage: perl $0 [PATH/][TO/]DIR\n"; exit; } my $path = $ARGV[0] ; sub list { my $path=$_[0]; #print "DEBUG - listing [$path]\n"; chomp(my @files = `ls -a $path`); my @dirs; foreach(@files) { if (-d "$path/$_" && $_ ne "." && $_ ne ".."){ push (@dirs , "$path/$_"); } } print "-------------------------------------\n"; print "Generating HTML doc for path = [$path]\n"; open(FHOUT, ">", "$path/index.html") or die "Can't open '$path/index.html':$!\n"; print FHOUT "<!DOCTYPE html>"; print FHOUT "<html><head>" . "<title>listing:</title>" . "</head><body>"; print FHOUT "<ol>\n"; foreach( @files ) { if ($_ ne "index.html" && $_ ne "." && $_ ne "..") { print FHOUT "<li>"; print FHOUT "<a href='$_'>Parent</a>"; } if (-d $_) { print FHOUT "&nbsp;&nbsp;(DIR)"; } print FHOUT "</li>"; #print FHOUT "<br/>\n"; } } print FHOUT "</ol>\n"; print FHOUT "</body></html>"; close(FHOUT); #foreach (@dirs) { # print "$_\n"; #} ####+++++++++++++++ ## Now visit other dirs recursively: foreach (my @dirs) { &list($_); } exit;

In reply to 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.