Prevent bash redirection to overwrite existing files

Using a bash command “set” we can prevent bash redirection to overwrite existing files. If the file bash.txt exist this command will overwrite it:
ls > bash.txt
To prevent it we can run command:
set -C
to disable run command:
set +o noclobber
Example:
$ ls > bash.txt
$ set -C
$ ls > bash.txt
bash: bash.txt: cannot overwrite existing file
$ [...]

Perl script code example to create temporary file-tempfile()

Here is a perl script example how to create temporary file on the file system:
TEMPLATE DIR AND SUFIX are option !

#!/usr/bin/perl
my $tempfile = new File::Temp ( TEMPLATE => ‘tempfile_XXX’, DIR => ‘/tmp/’, SUFIX => ” );

this will create a temporary file in /tmp/ directory with name tempfile_XXX where X is random generated character.

Perl script code example to create temporary directory-tempdir()

Here is a perl script example how to create temporary directory on the file system:

#!/usr/bin/perl
use File::Temp qw/ tempdir /;
my $perl_temporary_directory = tempdir();