#!/usr/bin/perl -w

# lab 03 solution

#----------------------------------------------------------------------

$testfile = '/mnt/homes/CLASSES/CIS2279/LAB03/test.jpg';

#    Accepts two (2) command line arguments: The first should set the test for temperature or relative humidity. The second should be a numeric data value.
#    The command would look something like this: lab03.pl RH 9
#    Checks the number of arguments and exits the program if the required arguments are not provided.
chomp($ARGV[$#ARGV]);
if ($#ARGV >= 1) {
    print "We have the correct number of arguments.\n";
}else{
    print "You are missing some arguments.  Exiting...\n";
    exit;
}

#    Checks that the second argument is numeric and prints an error message if it is not.
if(( $ARGV[1] =~ /\d/) && ($ARGV[1] !~ /\D/)) {
    print "Yes, we have a number for the second argument.\n";
}else{
    print "Second argument is not a real number.  Exiting.\n";
    exit;
}

#    If the first argument is for temperature, check that the value in the second argument is a reasonable value (ie. greater than -40F and less than 120F)
if ($ARGV[0] =~ /^temp/i) {
    if(($ARGV[1] <= 140) && ($ARGV[1] >= -40)) {
        print "Temperature is okay.\n";
    }else{
        print "Bad value for temperature.\n";
    }
}elsif ($ARGV[0] =~ /^rh/i) {
    if(($ARGV[1] <= 100) && ($ARGV[1] >= 0)) {
        print "RH: ok\n";
    }else{
        print "rh: loser\n";
    }
}else{ 
    print "weirdness...\n";
}
#    If the first argument is for relative humidity, check that the value of the second argument is a reasonable value (0-100).
#    Print to the screen a statement of whether the data value is within range.
#    For the following path, /mnt/homes/CLASSES/CIS2279/LAB03/test.jpg test for and print to the screen the following properties:
#        Is test.jpg a file or directory?
if( -d $testfile) {
    print "$testfile is a directory.\n";
}elsif( -f $testfile) {
    print "$testfile is a file.\n";
}else{
    print "I have no idea what this thing is.\n";
}

#        Is test.jpg readable?
if( -r $testfile ) {
    print "We can read $testfile\n";
}else{
    print "$testfile is not readable.\n";
}
#        Is test.jpg writeable?
if( -w $testfile ) {
    print "We can write to $testfile\n";
}else{
    print "$testfile is not writeable.\n";
}


exit;