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