Perl: checking command line arguments for basic sanity

Usage: ./your_script.pl 'path/to/file.txt'

Purpose: Check if argument has been supplied

# check files
if ( $ARGV[0] eq '')
{
  print "
###############
#    ERROR    #
 ###############
   
You have not specified an input file, please include the input file when you execute this script,
\n  
";
  exit;
}

Purpose: Check if file specifed in arguement exists

if (!-e $ARGV[0])
{
  print " 
###############
#    ERROR    #
###############
 
The input file you specified does not exist.

";
  exit;
}

Justin Kelly

Justin Kelly

Data Engineeer, Business Analytics, Web Developer, Library Technology specialising in PHP and Tableau

Based in Melbourne, Australia

Feel free to contact me justin@kelly.org.au or _justin_kelly