On Feb 10, 2004, at 7:34 AM, kynan wrote:

Is this a limitation?

No, it's a bug in your code. :-(


As Bill mentioned, the File::Find module is made for recursing through directories. It still might be useful for you to know what's going wrong, though.

sub replaceEkstros{

my $startDir = shift;

  # make an object out of the directory
  opendir DIR,$startDir || die $!;

Filehandles and dirhandles are global, so each time this sub is called, DIR is closed and re-opened on a new directory. To avoid that, pass a scalar to opendir() instead of a literal name. When a scalar is passed as the first parameter to open() or opendir(), it is used as the name of the filehandle/dirhandle to open. Likewise with readdir(), <>, read() and other functions that take filehandle/dirhandle parameters.


my $dh = $startDir;
$dh =~ s/\W/_/g; # Transform all non-alphanumerics to _

opendir $dh, $startDir || die $!;

while (my $entry = readdir($dh)) {

... and so on.

sherm--



Reply via email to