in reply to -s file test operator only works in same directory

$file contains the relative path (No directory name).

Early in your loop, you should probably update that to the full path :

$file = File::Spec->catfile($dir, $file);
ALso - Why are you using the strange "${\File::Spec...}" syntax ?

                All power corrupts, but we need electricity.

Replies are listed 'Best First'.
Re^2: -s file test operator only works in same directory
by Bowlslaw (Acolyte) on Dec 08, 2017 at 03:31 UTC
    Because subrefs are cool?
      That is not a subref.
      perl -E ' say ${\"FFF"}' FFF
      All you are doing is referencing then de-referencing the returned value of the sub.

      It is just a way to call a sub inside quotes - but I dislike the obfuscation it causes.

                      All power corrupts, but we need electricity.

        Ah, I see. Well, the real answer is that I left it like that because I was playing around, and I agree that it’s unnecessary. Also, I thought it was a subref. Anyway, thanks for your help!