I've been trying to debug this (very) simple program all morning, and so I don't think I'm seeing it right anymore. I've looked through my books and nodes on PM, but I have not found anything that helps.

What this is supposed to do is reproduce the file structure in one directory (recursively), but instead of copying the files it creates new ones with the same name (all with the same content contained in $redirect_page).

my $htdocs_dir = "/home/httpd/htdocs"; my $disabled_htdocs = "/home/httpd/htdocs_disable"; check_dir("."); #takes: a directory name sub check_dir { my $dir = shift; #defined $dir || $dir = ""; my $path = "$htdocs_dir/$dir"; opendir (DIR, $path) || die "Can't open $htdocs_dir/$dir: $!"; while (defined (my $dir_file = readdir DIR)) { if (-d "$path/$dir_file") { unless ($dir_file eq '.' || dir_file eq '..') { mkdir("$disabled_htdocs/$dir/$dir_file",0755); check_dir("$dir/$dir_file"); } } elsif (-f "$path/$dir_file") { add_file("$dir/$dir_file") } } #takes: file (with path) sub add_file { my $file = shift; open FILE, ">$disabled_htdocs/$file" || die "Can't open $file: + $!"; print FILE $redirect_page; print "wrote $disabled_htdocs/$file\n";##!! this never prints close FILE; } }
My problem is that it doesn't seem to be writing the files and only goes into one directory.

thanks, a very tired melguin.


In reply to simple recursive sub from hell. by melguin

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.