Here is a .pl file = IMSLOOK.pl, in this file i need to pull out some static variable value into a text file. so all the static var info will be retreive from the text file. To retreive the static info from the text file, there is another file loadconfig.pl which store the function to load the static info into the cgi file. emm sorry can one package call to another package?
here is the the part of the IMSLook.pl:
---------------------------------------
package IMSLook;
use Socket;
use CGI qw/:standard/;
require "LDAPLook.pl";
require "LDAPAdd.pl";
require "LoadConfig.pl";
# ----------------------------------------------------------# global v
+ariables
# ----------------------------------------------------------my %server
+con = &LoadConfig::LoadConfig("server.conf");
my $hostname = $servercon{'hostname'};
my $port = $servercon{'port'};
my $password = $servercon{'password'};
my $logdir = $servercon{'logdir'};
sub IMSConnect
{
my $response;
my $iaddr = inet_aton($hostname) || die "no host: $server";
my $paddr = sockaddr_in($port, $iaddr);
my $proto = getprotobyname('tcp');
# Open socket connection to the server
socket($sock, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
connect($sock, $paddr) || die "unable to connect";
select($sock); $| = 1; select(STDOUT);
&SOCKETread($sock);
&SOCKETwrite($sock, "LOGIN $password WRITE\n");
$response = &SOCKETread($sock);
if ($response =~ /.*OK.*/) {
&TaskLog("IMSLook sub::IMSConnect: Successfully connected
+to IMS\n");
return 0;
}
&TaskLog("IMSLook sub::IMSConnect: Access denied to IMS, possibly
+invalid password\n");
return 1;
}
Here is the part for the LoadConfig.pl function :
--------------------------------------------------
package LoadConfig;
use IO::Handle;
sub LoadConfig() {
$config_file = $_[0];
#open a file handle
open(MYHANDLE, "<$config_file") or die "could not open file";
while (<MYHANDLE>) {
chomp;
s/#.*//; # no newline
s/^\s+//;
s/\s+$//;
next unless length;
my ($var, $value) = split(/\s*=\s*/, $_, 2);
$User_Preferences{$var} = $value;
}
return %User_Preferences;
} # ~LoadConfig()
1;
here is the the part of the text file name Server.conf:
--------------------------------------------------------
hostname="sgsms.asia.com"
port="4200"
password="p"
logdir="C:\\tempperl"
host='sgsmld.d1asia.com:351'
host392='sgsmld.asia.com:352'
the problem is when i run, the apache server error log giving me the error that say i dun supply the host name for them. It mean the $hostname in (sub IMSConnect) didn't get any value can anyone check it for me. Thank you
Petruchio - Wed Jul 11 02:24:01 EDT 2001 - Added code and
p tags.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.