I am having a perl script which is taking a directory path as input and then script iterates through all the files present in that directory. For each file it calls some other function.
Here is the script:
#!/usr/bin/perl
use JSON;
use XML::Simple;
use File::Spec;
$num_args = $#ARGV + 1;
if ($num_args != 1) {
print "\nUsage: $0 <input directory>\n";
exit;
}
my $dir = $ARGV[0];
opendir(DIR, $dir) or die "cannot open directory";
@docs = grep(/\.xml$/,readdir(DIR));
foreach $file (@docs)
{
my $abs_path = join("",$dir,$file);
#print $abs_path;
my $return_object = some_function_call($abs_path);
print_output($return_object);
}
sub print_output
{
my $output_object = $_[0];
print $output_object;
}
My question here is when i am reading input directory, in case if does not exists how can make above script read from "Some Default Directory location". I tried adding some logic but did not work for me. This is my first perl script so please excuse me if this is too basic to ask.
I am working in LINUX environment.