in reply to [SOLVED]: Using glob in file test gives "Use of uninitialized value in -e" warning.

You've received good answers to your question. I would just add that it is debatable whether the useof the -e operator is useful here, since you're using it on directory entries just returned by glob. Note that since you mention it, using the -f operator would definitely be more useful because if would make it possible to apply your action only to regular files (therefore not trying to delete directories, for example).

Another comment is that it is usually considered a poor idea to use shell commands from a Perl script when there is an equivalent command in Perl. See unlink for details. Although if you really need to sudo, then it may be the only way.

  • Comment on Re: [SOLVED]: Using glob in file test gives "Use of uninitialized value in -e" warning.
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: [SOLVED]: Using glob in file test gives "Use of uninitialized value in -e" warning.
by afoken (Chancellor) on Dec 07, 2017 at 20:45 UTC
    Although if you really need to sudo, then it may be the only way.

    Even then, I would probably use sudo to run the perl script and use unlink in the script. Having to work with some random default shell is just a mess, and it can be quite dangerous with elevated privileges.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
      Yes afoken, you're most probably right.

      It's actually quite strange that I wrote "may be the only way," because I actually thought of sudoing the whole Perl script when I reflected on what I was going to write (and I wasn't quite sure of which of the two solutions would be better), but, for some reason, that thought somehow got completely out of my mind when I actually typed the message.