Hi,

Of course! This is the example of a script with recursive call that produces a 
list of the directory paths and filenames of all ".htm" and ".shtm" files 
contained within the subdirectory assigned to the $base variable.

__BEGIN__
#!/usr/local/bin/perl

$base = "/home/users/myspace/html/";
$delim = "/";

proc_files($base); 
proc_dirs($base);  # Prime the recursive call

print @out;

exit(0);

sub proc_files ($)
{
    my $subdir = shift;  # Called iteratively by proc_dirs
    my @files;

    opendir(DIR,$subdir);
    @files = grep{-f $subdir.$_;/\.html$/;} readdir(DIR);  # HTML files
    closedir(DIR);

    push(@out,"$subdir$_\n"); # stack result
}

sub proc_dirs ($)
{
    my $path = shift;  # Called by itself recursively
    my @subdirs;

    opendir(DIR,$path);
    @subdirs = grep {-d $path.$_; !/^\./} readdir(DIR);  # subdirectories
    closedir(DIR);

    foreach (@subdirs) {  # Process subdirectory files
        push(@out,$path.$_.$delim."\n");
        proc_files($path.$_.$delim);
        proc_dirs("$path$_$delim");  #  RECURSIVE CALL
    }
}

__END__

--
Regards,
Edward WIJAYA
SINGAPORE
Hi, everyone,
I want know whether perl support recursive sub routine call? if not, how I can meet this requirement?
 
thanks in advance.
 
Best regards,
-------------------------------------------------------------------------------------------------------------------------
TOPSEC, THE FIRST-CLASS SECURITY PRODUCTS AND SERVICES PROVIDER!
 
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Reply via email to