Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Having Trouble Recursing a Function

Reply
Thread Tools

Having Trouble Recursing a Function

 
 
Mark Healey
Guest
Posts: n/a
 
      02-24-2005
Can anyone tell me why the following only goes one level deep in the
directory tree?

I'm stumped


#!/usr/bin/perl

use strict;
use Cwd;

my $cdir;
my @files;

$cdir = getcwd();

doDir($cdir);

foreach(@files)
{
printf("$_\n");
}

exit;

sub doDir
{
my $dir = $_[0];
printf("####$dir####\n");
my $fname;
opendir(DIRHANDLE, $dir);
my @list = readdir(DIRHANDLE);
closedir(DIRHANDLE);
foreach(@list)
{
chomp;
if(-d $_)
{
unless(/\.\.?\z/)
{
$fname=$dir.'/'.$_;
doDir($fname);
}
}
else
{
if(/\.mp3\z/)
{
$fname=$dir.'/'.$_;
push(@files, $fname);
}
}
}# end foreach(@list)
}# end doDir()

TIA

--
Mark Healey
marknews(at)healeyonline(dot)com

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      02-25-2005
Jim Gibson <> wrote:
> In article <>, Mark Healey
><> wrote:
>
>> Can anyone tell me why the following only goes one level deep in the



>> my @list = readdir(DIRHANDLE);



>> if(-d $_)



> You
> need to check "$dir/$_" instead.



Just like it says in the documentation for the function that
the OP is using!

Asking hundreds of people to read the docs to you is not very nice...


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursing macro preprocessing? Henrik Goldman C++ 4 10-22-2006 05:25 AM
Recursing for Progress Bar half.italian@gmail.com Python 4 09-19-2006 04:53 AM
StackOverFlowException When Recursing Page Controls Randy ASP .Net Web Controls 1 01-19-2006 05:02 AM
recursing through files in a folder Scott Carlson Python 3 10-01-2004 05:51 PM
Recursing code problem snowdy C Programming 19 09-02-2003 04:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57