Hey Monks,

I have a piece of code I have to maintain (not the author) that handles automatic moving of files from one host to another. It uses 2 different methods, one of which is FTP.

A section of code from the main subroutine follows. The line I'm concerned with has an arrow next to it.

if( -d $filename ) { if( $promotion_method == $METHOD_FTP ) { ------> push( @global_files, recurse_dir( $filename ) ); } elsif( $promotion_method == $METHOD_RDIST ) { $filename =~ s/\/$//; push( @global_files, $filename ); } else { logmsg( 'docopy', 2, "PANIC!!!! No valid promotion met +hod defined!" ); exit( 1 ); } } else { push( @global_files, $filename ); }

The value of $filename is: /web/bazaar/html-docs/avantgo/, which I've verified using perl -d.

The recurse_dir subroutine is hanging and core dumping. It follows. You can see a recent change that I made to the code (the old code is commented out). I did this because the subroutine was returning a list of files with an extra slash after the value of $filename (e.g. /web/bazaar/html-docs/avantgo//index.html). My question is, have I inadvertently created some kind of endless loop here?

# Recursively process directories sub recurse_dir { my $filename = shift; my @results; # removed the "/" from the following; $filename has a trailing + "/" (if it's a dir) # so this was returning "//" -- Chris 12.28.2001 #my @list = glob( "$filename/*" ); my @list = glob( "$filename*" ); foreach my $file (@list) { if ( -d $file ) { push @results, recurse_dir( $file ); } else { push @results, $file; } } return @results; }

When I run this in the debugger (perl -d) I get messages such as the following, which make me curious, because I don't know much about the internals of glob. And because after a few iterations of recurse_dir, it core dumps.

main::go(docopy.pl:61): push( @global_files, rec +urse_dir( $filename ) ); DB<4> n File::Glob::csh_glob(/usr/local/lib/perl5/5.6.1/sun4-solaris/File/Glob +.pm:175): 175: if (wantarray) { 99 levels deep in subroutine calls!

Any comments or suggestions are appreciated (except for "use -w"... I would've if I'd written this, but if I use "-w" now everything breaks, and I need to get this running ASAP. Afterwards I'm going to re-write it.)

Thanks,

Chris

p.s. And if anyone knows how to get info from a core dump, that'd be helpful too!


In reply to recursive prob with glob? by alienhuman

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.