Check if something exists on the given path using the -e file-test statement.
print "$base_path exists!\n" if -e $base_path;
However, this test is probably wider than you expect. The above code will generate output if a simple file exists on this path, but it will also run for a directory, named pipe, symlink, or more exotic feature. See the documentation for more details .
Given the .TGZ extension in your question, it seems that you are expecting a simple file, not an alternative. The file-test -f statement asks if the path to a simple file leads.
print "$base_path is a plain file!\n" if -f $base_path;
The perlfunc documentation covers a long list of Perl file-test statements , which covers many situations that you will encounter in practice.
-r
The file is readable using uid / gid.-w
The file is writable using an effective uid / gid.-x
The file is executable using an effective uid / gid.-o
File belongs to effective uid.-r
The file is read using real uid / gid.-w
The file is writable using real uid / gid.-x
The file is executed using the real uid / gid.-o
File belongs to real uid.-e
The file exists.-z
File has zero size (empty).-s
The file has a nonzero size (returns the size in bytes).-f
A file is a simple file.-d
A file is a directory.-l
The file is a symbolic link (false if symlinks arent supported by the file system).-p
A file is a named pipe (FIFO), or Filehandle is a pipe.-s
A file is a socket.-b
A file is a special block file.-c
The file is a special character file.-t
The descriptor file opens in tty.-u
The file has a setuid bit.-g
The file has a setgid bit.-k
The file has a sticky bit.-t
The file is an ASCII or UTF-8 text file (heuristic assumption).-b
The file is a binary file (opposite -t ).-M
Script start time minus file modification time, in days.-A
The same goes for access time.-c
The same for inode change time (Unix may differ for other platforms).
Greg Bacon Apr 08 '10 at 15:10 2010-04-08 15:10
source share