Here is some code that may help you...
File::Find is a module that is most likely included in your Perl distribution without having to install anything.
Update: File::Find is a core module, so it is for sure in your installation. There are other similar modules. File::Find does the recursion without you having to think much about it.

Update:See following posts.. evidently some "system" Perls on Unix machines may not have all of the Core modules! Users are well advised to install their own Perl environment. I do most of my work nowadays on Windows (which doesn't come with Perl) so the issues are different. The code below is multi-platform (I tested on Windows), but you do need File::Find.

Pay attention to the error messages for invalid command line input.

#!/usr/bin/perl use strict; use warnings; use File::Find; my $path = shift; # what you expect to happen! # @ARGV contains one thing which is # a path to a directory. This shift removes # that path from @ARGV and it goes to $path # Now check if the "normal case" is correct or not... + usage("no directory specified") if !defined $path; usage("too many arguments. Only one dir allowed") if (@ARGV !=0 ); usage("$path does not exist") if (not -e $path); usage("$path is not a directory") if (not -d $path); sub usage { my $msg = shift; print STDERR "$msg\n"; exit (1); # exit(0) is success, all other values # mean a failure as per common practice } find(\&each_file, $path); # each_file() is called for every # file underneath $path. # Note that a directory is a special # kind of a file. -f tests if this name # is a "simple file". sub each_file { # your code goes below... # $File::Find::name is the current file in this recursive # descent underneath the directory $path # if (-f $File::Find::name) #a simple file (NOT ., .., Or any other d +irectory) { print "$File::Find::name\n"; #current file name # I would make an HTML sub to call here for that name.. } }

In reply to Re: How to perform recursion in any OS? by Marshall
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.