Perl – Global symbol $DIR requires explicit package name (why can’t I print the output?) [closed]

You get the error because you are using a variable ($DIR) you never declared. You do have a declared a variable named $dir which appears to be the one you intended to use.

glob "${dir}/*.csv"
glob "$dir/*.csv"
glob $dir."/*.csv"

Your code mishandles paths with spaces, *, ?, etc. Fix the injection bug using

glob "\Q${dir}\E/*.csv"
glob "\Q$dir\E/*.csv"
glob quotemeta($dir)."/*.csv"

Leave a Comment