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

Web Developer, Business Analytics, Data Engineer specialising in PHP, ReactJS, Tableau, AWS RedShift and Matillion ETL

Based in Melbourne, Australia

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

Leave a comment

Name Notify me of replies by email.