Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by Laurent_R (Canon)
on Dec 07, 2017 at 07:35 UTC ( [id://1205076]=note: print w/replies, xml ) Need Help??


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.

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1205076]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-19 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found