Whats wrong?

Hi, i just want to say that I am learning because this script's integrity im sure sucks but I think I have the idea. Basically, I am trying to extract the first name, last name and an email from a whois inquiry but it doesnt want to work..why?

#!/usr/local/bin/perl
$checkthis = "bannerweb.com";
&printtop;
&check_com;
&printbot;

sub check_com{
$com = `whois $checkthis`;
print ".\n";
if ($com =~ /No match for/i){} else {&getemailcom;}
}

sub getemailcom{
@coms = $com;
$x = 0;
foreach $strn (@coms){
      $strn = grep {"administrative"} $strn;
      if ($strn eq "administrative") {$x=1;} else {
      if ($x == 1) {
            ($fname,$lname,$mail) = $line=~/(\w+)\W+(\w+).*\s(\S+)/;
            $x = 0; &write;}
            }
      }
}

sub printtop{
   print "Content-type: text/html\n\n";
   print "<html><head><title>Working... just wait.</title></head>\n";
   print "<body bgcolor=#FFFFFF text=#000000>\n";
}

sub write{
$str = $firstname.",".$lastname.",".$mail;
print "$str\n";
}

sub printbot{
   print "</body></html>\n";
   exit;
}
MAXcomAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GnissmanCommented:
What do you mean by "it dosn't want to work"?
Does it return an error if you start it?
Does the whois-call return any values and is it just a matter of matching them the right way?

Any information could help ;-)

Gniss
0
bigbedCommented:
In function getemailcom() you probably want to do:
@coms = split $com

Also, your use of grep will set $strn to the number of times the word "administrative" appears in the line you are testing.
Perhaps you should do
if ( $strn =~ /administrative/i )
{
   $x = 1;
}
else
.... etc.
Also, the line:
($fname,$lname,$mail) = $line=~/(\w+)\W+(\w+).*\s(\S+)/;

should use $strn instead of $line.

Give that a try..
0
bigbedCommented:
Oops, that first line should be:
@coms = split /\n/, $com;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

MAXcomAuthor Commented:
Ok, here is the script with the changes; I still get the "500 Internal Server Error". I dont get it...

#!/usr/local/bin/perl
$checkthis = "bannerweb.com";
&printtop;
&check_com;
&printbot;

sub check_com{
$com = `whois $checkthis`;
print ".\n";
if ($com =~ /No match for/i){} else {&getemailcom;}
}

sub getemailcom{
$x = 0;
@coms = split /\n/, $com;
foreach $strn (@coms){
      if ($strn =~ /administrative/i)
           {
             $x = 1;
           } else {
      if ($x == 1) {
            ($fname,$lname,$mail) = $strn=~/(\w+)\W+(\w+).*\s(\S+)/;
            $x = 0; &write;}
            }
      }
}

sub printtop{
   print "Content-type: text/html\n\n";
   print "<html><head><title>Working</title></head>\n";
   print "<body bgcolor=#FFFFFF text=#000000>\n";
}

sub write{
$str = $fname.",".$lname.",".$mail;
print "$str\n";
}

sub printbot{
   print "</body></html>\n";
   exit;
}
0
MAXcomAuthor Commented:
Adjusted points to 100
0
bigbedCommented:
try running:
perl -c <scriptname>
from the command line - this may show up some errors.
Be sure that the perl program *really* resides at /usr/local/bin/perl on your server.
Be sure that the permissions on the script allow the web server to execute it (ie at least 555 permissions).
If you don't have access to the error logs of your web server, ask the sysops if there are any log entries for your script.
Sorry if you feel I'm teaching grandma to suck eggs, but these are things I often overlook...
0
bigbedCommented:
Also, just try running it from your command line - you'll just get the HTML printed out, but you'll also see if any errors are being generated..
0
MAXcomAuthor Commented:
The people I am hosting with are not letting me get command line access and they will not run it for me. What do I do? The perl path is correct and permissions are 755. No access to log enteries. :( HEELP!
0
ozoCommented:
Is
#!/usr/local/bin/perl
the first thing in the program?
does whois exist on the server?
Is it in your path?
Do you have permission to run it?
0
MAXcomAuthor Commented:
Ok, my server was screwed up I called em and they fixed it... some permission thing. It runs now but it doesnt give me any feedback for some reason. It prints the dot so I know it did the whois inquiry and after that nothing happens, i dont get any of the information i want. Am I going about this wrong?
0
bigbedCommented:
I tried running your script from my command line (had to change the perl path in the first line, but otherwise I changed nothing). I got the following:

Content-type: text/html

<html><head><title>Working</title></head>
<body bgcolor=#FFFFFF text=#000000>
..
Max,Bolotnikov,maxcom@INTERSERV.COM
</body></html>

Is this the sort of thing you're expecting?

We're running apache under Linux, with Perl 5.00503.

Following on from ozo's suggestion, perhaps you need to put in the full pathname to whois in the command, like:
$com = `/usr/bin/whois $checkthis`;

or whatever its path is on your machine.
Again, you may have to ask the sysops what the path is.
Generally in CGIs it is best to put in full pathnames to commands you run within the backticks, for security.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.