in reply to Re: Iterate trough a series of folders
in thread Iterate trough a series of folders

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.
  • Comment on Re^2: Iterate trough a series of folders

Replies are listed 'Best First'.
Re^3: Iterate trough a series of folders
by kennethk (Abbot) on Apr 04, 2016 at 18:52 UTC
    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.