in reply to Iterate trough a series of folders

The problem you are having is that readdir returns the directory contents without path information. You probably want to change that to
my @dirs = grep {-d "$dir/$_"} readdir($gdh);
or even better
my @dirs = grep {/[^.]/ and -d "$dir/$_"} readdir($gdh);
and
opendir (my $tdh, "$dir/$tumordirs") or die "Unable to open subdir";
or alternately change your working directory with chdir. You might also simplify your life by using File::Find.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: Iterate trough a series of folders
by BlueStarry (Novice) on Apr 04, 2016 at 18:32 UTC
    Thank you very much for your advice sir, it works, but i'm struggling understanding why yours works and mine not. By the way, your help is much appreciated.
      Using "$dir/$_" changes your paths from relative to absolute. Unless your working directory (the directory your shell was in when you executed perl) is equal to $dir, -d will be looking in the wrong place. This might be more obvious if you execute the code:
      #!/usr/bin/perl use strict; use warnings; use 5.10.0; my $dir = "C:/Users/ST/DesktopSample"; opendir (my $gdh, $dir) or die "Unable to open main directory"; say for readdir($gdh); closedir($gdh);

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.