CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: function returning incorrect values: Edit Log



jcpratap
New User

Aug 29, 2016, 11:52 PM


Views: 2620
function returning incorrect values

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

Code
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


(This post was edited by FishMonger on Aug 30, 2016, 6:23 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Aug 30, 2016, 6:23 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives