
Do use the HOME environment variable if it is present, because it is sometimes useful to change it to run a program with different configuration files, and the environment variable is always available in practice whereas the user database could be unavailable due to network trouble in some configurations (e.g. Make a directory for your scripts: mkdir perlscripts Go to that directory: cd perlscripts Use emacs and cut and paste to make a copy of the starter script. In our example, Perl was installed on the following directory.

Wait for the Perl installation to finish. Set the desired installation path and click on the Next button. Accept the license agreement and click on the Next button. If you like, you can fall back to querying the user database if HOME is not present, but that's an abnormal situation. As the administrator, start the Perl installation. The user's home directory is almost always available in the environment variable HOME.

If you'd used Perl's built-in mkdir function rather than calling an external command via a shell script, you would have had an error at that point because the directory ~ doesn't exist. Not in Perl and not in any other programming language, except the language of the current shell. People keep getting tasks to write a Perl script that can change directory that even after exiting the Perl script the change will persist.
#Perl mkdir how to
So the test done by -d fails, because there's no directory called ~. How to change directory (chdir, cd) in Perl chdir. This new directory is passed to the mkdir () command.

Below is a small program that reads the STDIN for a string, and then appends that string to an existing directory. As far as Perl or the kernel is concerned, ~ means a file or directory with a one-character name, like any other character. The short answer is yes, you can create a subdirectory using Perl's mkdir command. It's the shell that replaces ~ by the user's home directory. ~ is interpreted by the shell that is invoked by the system function.
