LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Use of uninitialized value in string eq (http://www.linuxquestions.org/questions/programming-9/use-of-uninitialized-value-in-string-eq-912840/)

moyorakkhi 11-10-2011 09:27 AM

Use of uninitialized value in string eq
 
Hi,

I have this script which rotate postfix outgoing IP periodically. This script was running fine with perl version 5.8.0. But having problem which running on a new server which has perl version v5.8.8. The error is:

Code:

Use of uninitialized value in string eq at ./test_aol.pl line 7.
Use of uninitialized value in string eq at ./test_aol.pl line 7.
Use of uninitialized value in concatenation (.) or string at ./test_aol.pl line 19.

The perl script is:

Code:

#!/usr/bin/perl -w

open(AOL_SWITCH, "</scripts/aol_switch.dat");
$ip = <AOL_SWITCH>;
close(AOL_SWITCH);

if($ip eq "xx.xx.xx.xx")
{
  $newip = "xx.xx.xx.xx";
  $host = "mail2";
}
elsif($ip eq "xx.xx.xx.xx")
{
  $newip = "xx.xx.xx.xx";
  $host = "mail3";
}

open(MAIN_CF_MAIN, "</etc/postfix/main.cf-main");
open(MAIN_CF, ">/etc/postfix/main.cf");

while(<MAIN_CF_MAIN>)
{
  print MAIN_CF $_;
}

close(MAIN_CF_MAIN);

print MAIN_CF "\n";
print MAIN_CF "smtp_bind_address = ".$newip."\n";
print MAIN_CF "myhostname = ".$host.".OURDOMAIN.com\n";

close(MAIN_CF);


open(AOL_SWITCH, ">/scripts/aol_switch.dat");
print AOL_SWITCH $newip;
close(AOL_SWITCH);

Thanks for your response in advance.

NevemTeve 11-10-2011 09:54 AM

Try '==' instead of 'eq'

moyorakkhi 11-10-2011 10:28 AM

Quote:

Originally Posted by NevemTeve (Post 4520743)
Try '==' instead of 'eq'

Thanks for you feedback NevemTeve. Now it's showing this error:


Argument "66.165.xx.xx" isn't numeric in numeric eq (==) at ./test_aol.pl line 7.
Argument "66.165.xx.xx\n" isn't numeric in numeric eq (==) at ./test_aol.pl line 7.

moyorakkhi 11-10-2011 10:46 AM

Well, I was able to resolve it. Gotta add the following line :)

use warnings;
use strict;
use threads;

my $ip;
my $newip;
my $host;

NevemTeve 11-10-2011 10:50 AM

Sorry, I was wrong 'eq' is the right operator -- most likely your file (/scripts/aol_switch.dat) is empty or non-existent.

moyorakkhi 11-10-2011 11:43 AM

Well, i guess it was too early to be happy. Having trouble :(

Use of uninitialized value in concatenation (.) or string at ./test_aol.pl

What else needs to be initiated for the line: print MAIN_CF "smtp_bind_address = ".$newip."\n"; ?

SecretCode 11-10-2011 12:09 PM

$newip might not be set if it doesn't match the if or elsif clauses. A standalone print "$newip\n"; will either show blank or error out. (Adding trace statements like this is the first thing I do when hit by puzzling errors.)

Also, you might need to chomp $ip; after reading from the file - one of your error messages shows that it contains a trailing newline.

moyorakkhi 11-10-2011 12:39 PM

Quote:

Originally Posted by SecretCode (Post 4520860)
$newip might not be set if it doesn't match the if or elsif clauses. A standalone print "$newip\n"; will either show blank or error out. (Adding trace statements like this is the first thing I do when hit by puzzling errors.)

Also, you might need to chomp $ip; after reading from the file - one of your error messages shows that it contains a trailing newline.

Thanks a lot dude! The chomp $ip; did it. I put the script in production server and working like charm :) Thanks again.


All times are GMT -5. The time now is 07:25 AM.