I'm converting a PHP script to perl so I can run it on the command line in Panther. The following sub routine is a cut down example of what one I'm using. It gets called once, passing the name of a directory. It is meant to recursively call itself for each directory it finds, so it work it's way down the 'branches' of the 'tree'. If it finds a directory any called "ekstro" it does some stuff.
In PHP it worked because it would be looping over one directory, find a directory and start looping over that. When it had gone through all the contents of that directory it would continue looping through the first one. This would just keep happening - directory within directory within directory etc.
My problem is that the perl script seems to work in a different way. It looks through the contents of one directory and, when it finds a directory it begins looping through the contents of that one. But when it's finished with that one the it doesn't continue looping through the first one again - ie. it goes down only one branch of the 'tree'.
Is this a limitation? Does perl work inherently differently to PHP in this respect? Do I have to forget about using perl?
sub replaceEkstros{
my $startDir = shift;
# make an object out of the directory opendir DIR,$startDir || die $!;
# while there is something in the directory to read, read it. while (my $entry = readdir(DIR)) {
if(-d "$startDir/$entry" && $entry =~ /^ekstro$/){
#do some stuff
}elsif(-d "$startDir/$entry"){
# call itself replaceEkstros("$startDir/$entry");
} } }
+
Kynan Hughes
phone 9281 2088 fax 9211 4433 mobile 0411 231099
Additive design pty ltd Amitabha pty ltd http://www.additive.net.au
Level 4, 104 Commonwealth St Surry Hills NSW 2010 Australia
+