Perl subroutine returning different values in HPUX

HI ,
I am running a program on hpux in perl.
I am encountering a strange issue where when i print a variable in the sub which is returning it , it prints a different value but when i call it and store value in a variable it gives a different o/p.

the sub is

sub CheckConfigFilePattern 
{ 
local($FILE) = @_; 
$intLineCount = 1; 
$intSendOpcmon = 0; 
$intCorrectFormat = 0; 

open(CONFFILEHDR, "< $FILE") or die "$!"; 
foreach $strLine (<CONFFILEHDR>) 
{ 
$strLine = trim($strLine); 
if( length($strLine) != 0) 
{ 
print "##############################\n"; 
print "$strLine \n"; 
print "step 0 \n"; 
if( $strLine !~ m/(^#)|(^\s*(\/|\d+)\s+(\/|\d+)\s+(\/|\d+)\s+(\/|\d+)$)/ ) 
{ 
OpcMsg("OS","minor","ConfigFileError","Error in Config File $FILE : Line No. $intLineCount, Text - $strLine","OpC"); 
$intSendOpcmon = 1; 
print "step 1 \n"; 
} 
if ( $strLine =~ m/(^\s*(\/|\d+)\s+(\/|\d+)\s+(\/|\d+)\s+(\/|\d+)$)/ ) 
{ 
$intCorrectFormat = $intCorrectFormat + 1; 
print "step 2 \n"; 
} 
} 
$intLineCount = $intLineCount + 1; 
} 
close CONFFILEHDR; 
if ( $intCorrectFormat != 1 ) 
{ 
OpcMsg("OS","minor","ConfigFileError","Error in Config File $FILE","OpC"); 
$intSendOpcmon = 1; 
print "step 3 \n"; 
} 
print "1st intSendOpcmon: $intSendOpcmon \n"; 

return $intSendOpcmon; 
} 

I am printing intSendOpcmon before retruning it inside sub.

Now I am calling it ,

$intSendOpcmon = CheckConfigFilePattern($CONFFILE); 
if ( $intSendOpcmon = 1) 
{ 
print "2nd intSendOpcmon:$intSendOpcmon \n"; 
exit 0; 
} 

But I am getting different values of retruned variable

#"./cHmem_util.pl" 1 
1st intSendOpcmon: 0 
2nd intSendOpcmon:1 

Please check why function is returning different values inside and outside
Code

Numeric comparison is == ( double equal )

if ( $intSendOpcmon == 1) 
{ 
print "2nd intSendOpcmon:$intSendOpcmon \n"; 
exit 0; 
}

thanks for the reply , now this part is resolved but again i am facing issue in a subsequent code where I am printing based on value of a variable.

code is below

$free = unpack("x64L", $struct_psd);
print "pages:$pages free:$free\n";
$mb = ($psize / 1024) * $pages;
$mb = $mb / 1024;
if( $free == 0)
{
        print "hi";
}

code is printing value of free in

print "pages:$pages free:$free\n";

but it is not printing "hi" based on value of $free which is 0

o/p is

pages:0 free:0

I wonder if it's ending up as a string or floating point for some reason. $free=int(....); may convert it to an integer which will play nicer with ==

HI ,
I resolved the error , actually it required use of a different perl at the shebang line.
after changing the perl path its working

thanks all for your support.

1 Like