We help IT Professionals succeed at work.
Get Started

Argument "WARNING" isn't numeric in numeric eq (==) at

Chris Gralike
on
1,191 Views
Last Modified: 2012-05-07
Hello Perl experts,

Im writting a subroutine for my startup script and I get the titles error. This subroutine is intended to write log entries based on various events that are triggered inside this script.

This is the subroutine i wrote;

Anyone any idea why perl thinks it is comparing a Interger instead of the expected string?

Rgrds,
#!/usr/bin/perl -w
#Currently used modules
use warnings;
use Getopt::Long;
use Config::Inifiles;
 
#The Sub
sub GenerateLogEntry{
        my $E_type = $_[0];
        my $E_msg = $_[1];
 
        if($E_type and $E_msg){
                # If no exit code was given we use 5
                $E_exit = scalar $_[2];
                if( ! $E_exit){
                        $E_exit = scalar '5';
                }
                if(open(FH, ">> $logFile")){
                        ($sec,$min,$hour,$mday,$mon,$year)=localtime(time);
                        $line = ($year+1900) . "-" . ($mon+1) . "-$mday $hour:$min:$sec \t => \t $E_type:$E_exit $E_msg\n";
                        print FH $line;
                        close FH;
                        if( $E_type == 'WARNING' or  $E_type == 'CRITICAL' ){
                                warn $line . "\n Was thrown!\n";
                        }
                }else{
                        warn "Unable to write event to logfile\nMessage contained:\n$E_type : $E_exit => $E_msg\n!";
                }
                #Handle the exit gracefull or forced
                if( $E_type == 'CRITICAL' ){
                        exit $E_exit;
                }
        }
}
####################################################
#Inside the code the subroutine is called like this;
 
GenerateLogEntry "CRITICAL","Configure the script using the $cfgFile file before rerunning this script!","1";

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE