grashoper has asked for the wisdom of the Perl Monks concerning the following question:

I have a problem with the following subroutine(s).. my problem is that default.config is being returned even though a config file for the site exists
I have other sites that don't exhibit this behaviour and I am puzzled as to why this one account has a problem,
of course its the one I need to modify. This is a support portal and services something like 30 different accounts
, some of these accounts have livechat some do not, the config file controls whether or not the live chat displays.
the xml itself exists in SQL as well as statically on the site and gets recreated if deleted by the sql, yes it has been changed on the sql right now the data push from the sql is not working either

ex subroutine 1..

sub getConfig { #This is for site/account specific options my $str = ""; my $xml = xmlFileData("Config",$Session->{'usrSystem'}.".config.xm +l","getConfig()"); if (!$xml) { $xml = xmlFileData<br>("Config","_default.config.xml","getConfig( +)"); } { $xml =~ /<system>(.*?)<\/system>/s; $str .= $1; } { $xml =~ /<account id="$Session->{'usrAccount'}"> (.*?)<\/account>/s; $str .= $1; } return $str; }

My other subroutine..

sub config { my $str = "<config>"; my $browser = $Request->ServerVariables("HTTP_USER_AGENT")->item() +; SWITCH: { if ($browser =~ /MSIE/) { $browser = "MSIE"; last SWITCH; } if ($browser =~ /Firefox/) { $browser = "FireFox"; last SWITCH; } } $str .= "<system>$Session->{'usrSystem'}</system>"; $str .= "<account>$Session->{'usrAccount'}</account>"; $str .= "<password>$Session->{'usrPassword'}</password>"; $str .= "<browser>$browser</browser>"; $str .= "<mode>$Session->{'mode'}</mode>"; $str .= "<codeBase>$Session->{'version'}</codeBase>"; $str .= "<usersOnline>".$Application->{'currentUserCount'}."</user +sOnline>"; # if($Session->{'trainingDelegate'}) # { # $str .= "<trainingDelegate>True</trainingDelegate>"; # } if ($Session->{'acrobatVersion'} >= $Session->{'minAcrobatVersion' +} || $Request->ServerVariables("HTTP_USER_AGENT")->item() =~ /Mac/) { $str .= "<acrobatReaderFound version=\"".$Session->{'acrobatVers +ion'}."\"/>\n"; } else { $str .= "<acrobatReaderNotFound/>"; ### chat pulls from here #### } if (getConfig() =~ /(<includeLiveHelp.*?)\/>/s) { $str .= $1." system=\"".$Session->{'usrSystem'}."\" account=\"".$Session->{'usrAccount'}."\" username=\"".$Session->{'usrID'}."\" password=\"".$Session->{'usrP +assword'}."\"/>"; } $str .= "</config>"; return $str; }

Sorry if the format is a little messy I am new here :)

Replies are listed 'Best First'.
Re: problems with xml data being returned
by runrig (Abbot) on Jul 18, 2007 at 19:57 UTC
    First, welcome, and wrap your code in <code></code> tags.

    From your description, it seems like all you needed to post was the first 7 or 8 lines of code, and I have no idea what xmlFileData() is doing, but my guess is that it's not returning what you want it to return, maybe because you're not passing what you think you're passing to it. I'd check the values of the arguments you're passing to it to make sure they are what you think they are (maybe an errant linefeed or other control character is sneaking in?) Is "getConfig()" supposed to be a string, or should it be a function call?.

      XMLFileData is yet another subroutine its reading the files. I am new to perl and having trouble understanding what the code means it wouldn't be so bad but I didn't write it and its quite large and not all that modular either :( ah code tags..I thought there must be an easier way.
        I can't look any more deeply at the problem until you look closely at these two lines:
        my $xml = xmlFileData("Config",$Session->{'usrSystem'}.".config.xm +l","getConfig()"); if (!$xml)
        I have no idea what the arguments are, and even if I did know what the args were, I don't really feel like debugging the bunch of code in xmlFileData that you just posted. So, like I said before, check the arguments. If the arguments look ok, debug what's happening in xmlFileData(). Look at one thing at a time until you find out what the problem is. Try reading brian's Guide to Solving Any Perl Problem.
      getConfig() is a a function call.
Re: problems with xml data being returned
by grashoper (Monk) on Jul 18, 2007 at 21:34 UTC
    getconfig() is a function.. I am including xmlfiledata in case it helps..I really need help to solve this one
    <blockquote> sub xmlFileData { use OLE; my ($path, $file, $caller) = @_; my $sPath = $path; $sPath =~ s/\///g; my $xml = ""; my $xmlFSO = CreateObject OLE "Scripting.FileSystemObject"; if ($Application->{"cxml_".$sPath.$file} && ($Application->{"cxml_ +".$sPath.$file."_dlm"} - time) > (5 * 60 * 60) && !$Session->{'forceF +iles'}) { #refreshed < n minutes ago, consider fresh } else { my $Conn = CreateObject OLE "ADODB.Connection"; my $RS = $Server->CreateObject("ADODB.Recordset"); $Conn->Open("PROVIDER=SQLOLEDB;DATA SOURCE=$Session->{'sqlServer +'};UID=$Session->{'sqlUser'};PWD=$Session->{'sqlPass'};DATABASE=$Sess +ion->{'dbName'}"); if ($Conn) { #CONN OK if ($Session->{'forceFiles'} && $Application->{"cxmlF_".$sPath +.$file."_dlm"}) { if ($Application->{"cxmlF_".$sPath.$file."_dlm"} ne $xmlFSO- +>GetFile($Server->MapPath("$path/$file"))->{'DateLastModified'}) { my $sql = "UPDATE XMLFileData SET Active='0' WHERE Path='$path' AND FileName='$file';"; $RS = $Conn->Execute($sql); } } if ($Session->{'cacheData'}) { my $sqlDLM = ""; my $sqlBody = ""; my $dumpFile = 0; my $setSQL = 0; my $sql = "SELECT LastModify, Body FROM XMLFileData WHERE Active='1' AND Path='$path' AND FileName='$file';"; if ($Session->{'trackDB'}){lg("DB","xmlFileData($sql)");} $RS = $Conn->Execute($sql); if ($RS) { if (!$RS->EOF()) { $sqlDLM = $RS->Fields('LastModify')->{Value}; $sqlBody = $RS->Fields('Body')->{Value}; $RS->Close; } } if ($sqlDLM) { if ($sqlDLM eq $Application->{"cxml_".$sPath.$file."_dlm"} +) { #SQL_dlm=App_dlm USE APP $xml = "<app/>"; } else { #SQL_dlm!=App_dlm USE SQL SET APP DUMP FILE $xml = "<sql/>"; $Application->Lock(); $Application->{"cxml_".$sPath.$file."_dlm"} = $sqlDLM; $Application->{"cxml_".$sPath.$file} = $sqlBody; + $Application->Unlock(); $dumpFile++; } } else { if ($Application->{"cxml_".$sPath.$file} && !($Session->{' +forceFiles'} && $xmlFSO->GetFile($Server->MapPath("$path/$file"))->{' +DateLastModified'} ne $Application->{"cxmlF_".$sPath.$file."_dlm"})) { #SQL=N App=Y USE APP SET SQL $setSQL++; } else { #SQL=N App=N if ($xmlFSO->FileExists($Server->MapPath("$path/$file")) +) { $xml = "<file/>"; #SQL=N App=N File=Y USE File SET SQL SET APP $Application->Lock(); my $xmlHandle = $xmlFSO->OpenTextFile($Server->MapPath +("$path/$file"),1); $Application->{"cxml_".$sPath.$file} = $xmlHandle->Rea +dAll(); $Application->{"cxml_".$sPath.$file."_dlm"} = $Applica +tion->{"cxmlF_".$sPath.$file."_dlm"} = $xmlFSO->GetFile($Server->MapP +ath("$path/$file"))->{'DateLastModified'}; $Application->Unlock(); $xmlHandle->Close(); $setSQL++; } else { #SQL=N App=N File=N Hope for the Best and Some better error reporting } } } if ($dumpFile) { #uncomment this stuff when ability to modify is on. my $fFSO = CreateObject OLE "Scripting.FileSystemObject"; my $fHandle = $fFSO->OpenTextFile($Server->MapPath("$path/ +$file"), 2, True); $fHandle->WriteLine($Application->{"cxml_".$sPath.$file}); $fHandle->Close(); $fHandle = undef; $fFSO = undef; } if ($setSQL) { my $sql = "INSERT INTO XMLFileData (Active, LastModify, Path, FileName, Body) VALUES ('1', {fn NOW()}, '$path', '$file', '".$Appli +cation->{"cxml_".$sPath.$file}."')"; if ($Session->{'trackDB'}){lg("DB","xmlFileData($sql)");} $RS = $Conn->Execute($sql); } $xml = $Application->{"cxml_".$sPath.$file}; } else { #No Cache,. don't be retarded,. turn it back on. } } else { #CONN BAD } } return $xml; }