elsif(($#ARGV+1) < 1) {
is a bit strange. First, it would be simpler to test:
elsif ($#ARGV < 0) {
(Note that if no argument is passed, $#ARGV will be -1.)
Second, if you want to test the number of arguments passed to the program, it is clearer to evaluate @ARGV in scalar context (which gives the number of items in that array):
elsif (@ARGV < 1) {
# or, if you prefer an explicitly stated scalar context:
elsif (scalar @ARGV < 1) {
Last, but not least, this conditional statement will never be true because, if you don't pass any argument, this statement will not be executed: the program will die with the first conditional
if(! -e "$Dir") {
In fact, it is quite strange to check if an argument is passed after having checked whether the value of the argument is a valid directory.
So if you want to check that at least one argument is being passed to the program, you should do it first.
Also, it is a bit useless to check for the existence of $Dir and then whether it is a valid directory (unless you want to print a different message in that case); you can check directly that it is a valid directory.
So, this program could be rewritten as:
use strict;
use warnings;
die "Please supply an argument to the program" if @ARGV < 1;
my $dir = shift;
die "Please try again with a valid directory.\n" unless -d $dir;
# Change to user selected location
chdir $dir;
mkdir "FirstSubDir";
mkdir "SecondSubDir";
|