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