Path: utzoo!attcan!uunet!mcsun!cernvax!chx400!lengge From: lengge@chx400.switch.ch (Thomas Lenggenhager) Newsgroups: comp.lang.perl Subject: Recursive Subroutines - Help sought Message-ID: <1990Oct29.140931.5498@chx400.switch.ch> Date: 29 Oct 90 14:09:31 GMT Organization: SWITCH Lines: 64 I am just a beginner with perl. I use it on a SUN 4/490, the version is $Header: perly.c,v 3.0.1.8 90/10/16 10:14:20 lwall Locked $ Patch level: 36 This is my first perl program which should list all file entries of a directory recursively. However what it does is listing the files of the directory I give as input and the files of the first subdirectory but then the program stops! It seems to me, that some variables are not recovered correctly on returning from the subroutine, even by declaring them as local. I know that I could have that much more easily, but the main intent was to do some processing on each file of a sub-tree. Who can find the bug in my program, or who suggests a better solution to my problem. Many thanks for your help in advance, Thomas Lenggenhager SWITCH =============================================================================== Thomas Lenggenhager, SWITCH, ETH-Zentrum, CH-8092 Zurich, Switzerland INET: lenggenhager@verw.switch.ch | Tel: +41-1-261'8178 UUCP: ..!mcsun!chx400!lenggenhager | Fax: +41-1-261'8133 X.400: S=lenggenhager;OU=verw;O=switch;P=switch;A=arcom;C=ch Here follows my perl program: =============================================================================== # # Ask for directory name and list fileentries recursively # print "Directory: "; $dirname = ; chop($dirname); do read_dir($dirname); exit; sub read_dir { # # Print all full filenames recursively to STDOUT # local($dirname) = @_; local($file, $filename); open($file, "/bin/ls -AF $dirname|") || return ; while (<$file>) { $filename = $_; chop($filename); if ($filename =~ s|/$||) { $dirname = $dirname . "/" . $filename; print $dirname, "/\n"; do read_dir($dirname); } else { print $dirname . "/" . $filename, "\n"; } } close($file); } -- =============================================================================== Thomas Lenggenhager, SWITCH, ETH-Zentrum, CH-8092 Zurich, Switzerland INET: lenggenhager@verw.switch.ch | Tel: +41-1-261'8178 UUCP: ..!mcsun!chx400!lenggenhager | Fax: +41-1-261'8133