perlquestion
tame1
UPDATE: Seems that the data I was testing for landed right on a buffer chunk boundary. Not good. Let that be a lesson to all us part timers - boundaries suck!<br>
====================================================<br>
Recently, I had to drag my old perl knowledge up from the bottom of my brain to do a little db creation work.<br><br>
I am taking a web page from our local chamber of commerce, where they give an alphabetical listing of their members, and sucking it in with Net::HTTP. I then cycle through the $buffer looking for occurances of "ID=XXXX". Those are links to "more info" on each company. Using the built-up array of IDs, I then pull each companies individual data.<br><br>
Anyhow, to make a long story short (too late, right?) one business, serial number 3975, is always skipped!!! the regex <code>$buf =~ /ID=([0-9]+)/</code> seems to think 3975 doesn't match! The only answer I have found is to first write the main web page to a file, then read in the file. THEN it matches.<br><br>
Here is the code I am/was using:<br><br>
<code>
#!/usr/bin/perl
use strict;
use Net::HTTP;
use HTML::Strip;
use LWP::Simple;
my $DOMAIN="www.fentonchamber.org";
my $MAIN_LIST="AlphabeticalListing.asp";
my $HOMEDIR="/home/jrobiso2/Documents/CDS/Chamber/";
my $list_file="/tmp/AlphabeticalListing.html";
my @listing;
### Get initial listing of data from the main page.
open(SRC, "+>$list_file") or die "Cannot open file: $!\n";
my $http = Net::HTTP->new(Host => $DOMAIN) || die $!;
$http->keep_alive;
$http->write_request(GET => "/$MAIN_LIST", 'User Agent' => "Mozilla/5.0");
my($code, $mess, %h) = $http->read_response_headers;
## Build the listing of company numbers from the javascript window.open
## calls inside the main listing html page.
while (1) {
my $buf;
my $n = $http->read_entity_body($buf, 1024);
die "read failed: $!" unless defined $n;
last unless $n;
# if ($buf =~ /ID=([0-9]+)/) { # OLD CODE
# push @listing, $1; # THAT FAILED
# } #
print SRC $buf;
}
close(SRC);
open(SRC, "<$list_file") || die "Cannot open file: $!\n";
while (<SRC>) {
if (/ID=([0-9]+)/) {
push @listing, $1;
}
}
@listing = sort @listing;
</code>
From the code above you can see the actual site and page I am trying to steal from. If anyone can enlighten me as to what is wrong (what I have done wrong) I would greatly appreciate it, as this has taken 3 hours of my time and made me feel very stupid.
I am using perl 5.8.6.
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-38148">
<br><br><font size="-3">What does this little button do . .<code><Click></code>;
"USER HAS SIGNED OFF FOR THE DAY"</font>
</div></div>