LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-10-2011, 09:27 AM   #1
moyorakkhi
Member
 
Registered: Jan 2011
Location: Dhaka
Posts: 80

Rep: Reputation: 1
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.
 
Old 11-10-2011, 09:54 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,713

Rep: Reputation: 488Reputation: 488Reputation: 488Reputation: 488Reputation: 488
Try '==' instead of 'eq'
 
Old 11-10-2011, 10:28 AM   #3
moyorakkhi
Member
 
Registered: Jan 2011
Location: Dhaka
Posts: 80

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by NevemTeve View Post
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.
 
Old 11-10-2011, 10:46 AM   #4
moyorakkhi
Member
 
Registered: Jan 2011
Location: Dhaka
Posts: 80

Original Poster
Rep: Reputation: 1
Well, I was able to resolve it. Gotta add the following line

use warnings;
use strict;
use threads;

my $ip;
my $newip;
my $host;
 
Old 11-10-2011, 10:50 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,713

Rep: Reputation: 488Reputation: 488Reputation: 488Reputation: 488Reputation: 488
Sorry, I was wrong 'eq' is the right operator -- most likely your file (/scripts/aol_switch.dat) is empty or non-existent.
 
Old 11-10-2011, 11:43 AM   #6
moyorakkhi
Member
 
Registered: Jan 2011
Location: Dhaka
Posts: 80

Original Poster
Rep: Reputation: 1
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"; ?
 
Old 11-10-2011, 12:09 PM   #7
SecretCode
Member
 
Registered: Apr 2011
Location: UK
Distribution: Kubuntu 11.10
Posts: 562

Rep: Reputation: 102Reputation: 102
$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.
 
1 members found this post helpful.
Old 11-10-2011, 12:39 PM   #8
moyorakkhi
Member
 
Registered: Jan 2011
Location: Dhaka
Posts: 80

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by SecretCode View Post
$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.
 
  


Reply

Tags
perl


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] uninitialized harddisk divyashree Linux - Newbie 4 01-19-2011 03:19 AM
Notice: Uninitialized string offset: 1 in [PHP] TheIndependentAquarius Programming 8 11-10-2010 10:09 PM
[SOLVED] copy string a to string b and change string b with toupper() and count the chars beep3r Programming 3 10-22-2010 07:22 PM
STL String: Uninitialized or some null value Ephracis Programming 9 03-04-2008 01:27 PM
Test uninitialized variable AMMullan Programming 6 02-12-2004 10:29 AM


All times are GMT -5. The time now is 04:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration