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.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");
Thank you
best wishesedited: Sun Jun 1 15:55:03 2003 by jeffa - title change (was: good solution ...)
In reply to Reformatting while traversing directories by star7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |