Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: "Deep recursion" error

by cspctec (Sexton)
on Jun 28, 2013 at 17:53 UTC ( #1041302=note: print w/replies, xml ) Need Help??

in reply to "Deep recursion" error

Thanks for the suggestions guys. The file globbing thing I was doing doesn't seem to be working out. I feel like I'm close, but I just can't get the script to descend into directories. I really wanted to use recursion to do this, for practice mainly.

I started over using opendir and readdir. Maybe file globbing just doesn't work properly with recursion, or maybe its just me.

Replies are listed 'Best First'.
Re^2: "Deep recursion" error
by poj (Monsignor) on Jun 28, 2013 at 19:07 UTC

    Yes, you are close ..

    #!perl use strict; use Cwd; # pwd has line ending, use this my $dir = cwd(); # protect against endless loop just in case ! my $limit = 10_000; # call with parameter start($dir); sub start { my $dir = shift; # add / to descend foreach (<$dir/*>) { die "exceeded limit" if --$limit < 0; print " $_ is file\n" if (-f $_); if (-d $_) { print "$_ is a dir\n"; start($_) } } }
      Thank you poj, that works perfectly.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041302]
and a log crumbles through the grate...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2018-06-19 15:21 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.