Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

can anyone help to detect any error in this script

by Anonymous Monk
on Jul 11, 2001 at 09:51 UTC ( #95605=perlquestion: print w/replies, xml ) Need Help??

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

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.

Replies are listed 'Best First'.
Re: can anyone help to detect any error in this script
by Abigail (Deacon) on Jul 11, 2001 at 11:00 UTC
    Your data file has quotes around the variables. You never strip the quotes, or do something with the double backslash for that matter. "sgsms.asia.com" is not a valid hostname, because quotes are not allowed in a hostname. Nor is "4200" an integer. Or "C:\\tempperl" a directory.

    The error log says you didn't supply a host name because of your bogus die message. Fix your die message and you'll get better error messages.

    -- Abigail

Re: can anyone help to detect any error in this script
by alfie (Pilgrim) on Jul 11, 2001 at 10:07 UTC
    Please use <code> tags around your code - it's not readable without, as you might be able to see...

    Update: Now that the <code> tags are added, it seems that you should have the quotes around the hostname too in the $hostname variable. Please try to die with $hostname and not $server to see what you really have in that variable. I don't know what exactly the inet_aton function does if it gets bogus input, but that might be the problem.
    --
    use signature; signature(" So long\nAlfie");

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://95605]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2022-05-27 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (95 votes). Check out past polls.

    Notices?