in reply to Yet another problem with recursive code

In addition, this code is weird:
if (defined (@ARGV) $ARGV[0]=~/-all/) { $mode="all"; } else { $mode=""; }
What is that $ARGV[0]=~/-all/ doing out there? Do you want an && or and in there? Also:
if (-d $file) { &scandir;
You're not chdiring into $file first, nor are you passing that to &scandir, so it looks to me like it's just going to repeat itself in the current directory/context again.

You're also calling &scandir twice in your code.. once towards the top and once at the bottom (for "."). Not sure if you intended to do that or not.

It looks to me like you need to figure out how you're wanting your functions to be called, and perhaps re-work the way you're passing arguments around.

Take a look at File::Find and File::Recurse also.

Replies are listed 'Best First'.
(tye)Re: Yet another problem with recursive code
by tye (Sage) on Nov 10, 2000 at 04:51 UTC

    Never use defined() on arrays nor on hashes because it doesn't mean what you think it means. You want one of these:

    if( @ARGV && $ARGV[0] eq "-all" ) { if( 0 < @ARGV && "-all" eq $ARGV[0] ) {
    An empty array can still be "defined" (or un"defined"), depending on obscure details about its history. Also, $ARGV[0] =~ /-all/ will be true if your first argument is "tell-all books", for example, probably not what you wanted.

            - tye (but my friends call me "Tye")