Hi,
I wrote a long script in perl. Now i have a problem. A part of my code:
sub textsformat { # variables: initialization ... ... ... my $text =$_[0]; open (MYFILE, "<$text") || die "the file $text is not readable: $!" ; open (OUTPUT, ">$text.txt") || die "can not open $text\.txt with the permission write: $!"; LINE: while(<MYFILE>) { ..... # Algo for formatting a textfile }; close(MYFILE); close(OUTPUT); }; sub dir_explorer { my $entry = $_ ; if (-d $entry) { ... # ignore . and .. opendir(DIR, $entry) or die "Can not open $entry: $!"; open(FILE, ">>$entry.tab") or die "Can not open $entry with the p +ermission write: $!"; while( defined (my $file = readdir DIR) ) { if (-f "$entry/$file") { textsformat("$entry/$file"); # .... }; }; close(FILE); closedir(DIR); }; }; find(\&dir_explorer, "/home/dub/S/programming/perl/dp");
the subroutine dir_explorer goes through the indicated directory recursively. For each text file in a directory the subroutine textsformat is invoked. Intention: successively: for each textfile of a directory the subroutine textsformat is invoked ,following the new formatted text file has to be inserted into the textfile (see open(FILE, ">>$entry.tab"), which contains all formatted textfiles of a directory.How can I solve the problem as best. Also I want to assign the name of the visited directory as parameter to the subroutine textsformat. Please indicates also the suitable code. I hope you understand my problem.

Thank you

best wishes
star7

edited: Sun Jun 1 15:55:03 2003 by jeffa - title change (was: good solution ...)


In reply to Reformatting while traversing directories by star7

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.