Thanks Sherm, Mike and Bill,

Totally helpful and much appreciated.

K

On 11/02/2004, at 1:27 AM, Sherm Pendley wrote:

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--


+

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

+



Reply via email to