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: Intermediate:
Maps and servers/documents

 



Jono
stranger

Aug 14, 2001, 3:40 AM

Post #1 of 1 (438 views)
Maps and servers/documents Can't Post

Hi All,

I've written two perl scripts...One to go through a number of directories and bring some data back from records in a file, the other to take a list of e-mail addresses, construct a query from them then run it and extract information from the returned HTML page.
I'd like to put them together if possible, and I need your help to do it:)

This is the program at the moment: Please excuse poor programming I'm not very good I know, but I'm learning;)

#!/usr/local/bin/perl -w
#use strict;

$search1 = "staff?id";
$search2 = "staff";
$search2a = ">";
$search3 = "</A>";
$search4 = qq!<TR><TD><FONT FACE="ARIAL,HELVETICA,SANS" SIZE="2">Tel</TD><TD><FONT FACE="ARIAL,HELVETICA,SANS" SIZE="2">!;
$search5 = "Tel";
$search6 = qq!</TD><TD><FONT FACE="ARIAL,HELVETICA,SANS" SIZE="2">!;
$search7 = "</TD>";

$filename = "../../../../software/KSE/main/data/stores/";
$server = "directory.intra.company.com";
$document = "$query$_->[2]";
my $query = '/ids/owa/people.quick?search_for=';

use IO::Socket;


print "Content-type:text/html\n\n";
print <<EndOfText;
<html>
<head>
<title>Jono's program for John Davies</title>
<style type="text/css">

</style></head>

<body bgcolor="#99cccc" text="#003333" link="#0000cc" vlink="#000099" alink="#cc0033">
<p><font size="+3">List of files</font></p>


EndOfText


opendir (LOGDIR, "$filename") || print " Bummer\n";
@logfiles = readdir (LOGDIR);
closedir(LOGDIR);
if (@logfiles) {

foreach $filenames (@logfiles) {


opendir (LOGDIR2, "$filename$filenames"); # || print " Arse, why doesn't this work?\n";
@logfiles2 = readdir (LOGDIR2);
closedir(LOGDIR2);
if (@logfiles2)
{
foreach $filenames2 (@logfiles2) {
if ($filenames2 eq "profiles")
{

my ($prf) = join($filenames,$filename,"/profiles");
my $query = '/ids/owa/people.quick?search_for=';
print("<p><b>$filenames</b><p>");
print qq!<table border="1" width="100%">!;
print("<tr>");
print qq!<td width="25%"><b>Name</b></td>!;
print qq!<td width="25%"><b>e-mail address</b></td>!;
print qq!<td width="25%"><b>OUC</b></td>!;
print qq!<td width="25%"><b>Telephone Number</b></td>!;
print("</tr>");

open INFILE2, "$prf" or die "cannot open address.txt: $!\n";

print map "<tr>".
"<td>$_->[0]&nbsp</td>".
"<td>$_->[2]&nbsp</td>".
"</tr>",


map [
grep !/^\s*$/,
split /(?:\r?\n)+/
],
grep !/^\s*$/,
grep /\@company.com/,

split /----------/,
do {
local $/=undef;

$remote = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>$server, PeerPort=>"80", Reuse=>1)
or die "Can't connect to \"$server\"\n";
# set buffering off
$remote->autoflush(1);
# write HTTP request to server
print $remote "GET $document HTTP/1.0\n\n";
# receive everything the server sends and print it to the screen
while (<$remote>) {
if (index($_, $search1) >= 0) { #ie does the line contain $search1?
($firstbit, $secondbit) = split($search2, $_, 2);
($thirdbit, $fourthbit) = split($search2a, $secondbit, 2); #split it into 2 at $search2
($fifthbit, $sixthbit) = split($search3, $fourthbit, 2); #split this bit into 2 at $search3
print("<tr>");
print("<td width='25%'>$fifthbit</td>"); #et voila!
}
if (index($_, $search4) >= 0) { #ie does the line contain $search1?
($firstbita, $secondbita) = split($search5, $_, 2);
($thirdbita, $fourthbita) = split($search6, $secondbita, 2); #split it into 2 at $search2
($fifthbita, $sixthbita) = split($search7, $fourthbita, 2); #split this bit into 2 at $search3
print("<td width='25%'>$fifthbita&nbsp</td>"); #et voila!
print("</tr>\n");

last;
}
}

close $remote;
<INFILE2>
};






close INFILE2;

print "</table><p>";


}
}
}
}
}



print "</body></html>";I managed to get the program to print out only e-mail addresses that end in @company.com and now I'd like to construct the query for each e-mail address and run it as it goes through the directories, then 'processing' the returned HTML and getting the necessary data from it. I know this bit works:
$remote = IO::Socket::INET->new(Proto=>"tcp", PeerAddr=>$server, PeerPort=>"80", Reuse=>1)
or die "Can't connect to \"$server\"\n";
# set buffering off
$remote->autoflush(1);
# write HTTP request to server
print $remote "GET $document HTTP/1.0\n\n";
# receive everything the server sends and print it to the screen
while (<$remote>) {
if (index($_, $search1) >= 0) { #ie does the line contain $search1?
($firstbit, $secondbit) = split($search2, $_, 2);
($thirdbit, $fourthbit) = split($search2a, $secondbit, 2); #split it into 2 at $search2
($fifthbit, $sixthbit) = split($search3, $fourthbit, 2); #split this bit into 2 at $search3
print("<tr>");
print("<td width='25%'>$fifthbit</td>"); #et voila!
}
if (index($_, $search4) >= 0) { #ie does the line contain $search1?
($firstbita, $secondbita) = split($search5, $_, 2);
($thirdbita, $fourthbita) = split($search6, $secondbita, 2); #split it into 2 at $search2
($fifthbita, $sixthbita) = split($search7, $fourthbita, 2); #split this bit into 2 at $search3
print("<td width='25%'>$fifthbita&nbsp</td>"); #et voila!
print("</tr>\n");

last;
}
}

close $remote;

Because it worked on its own. I'd just like to get it tow work for each e-mail address that is returned by the first part of the program. I know it's not in the right place in the code, but if you could help me to rewrite it so that it would work I'd be soooooo grateful.

Cheers,
Jono Wilkinson




 
 


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

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