On Thu, 9 Aug 2001, Scott Schultz wrote:
> However, the examples make it look as if the prog method program is
> nothing more than a sort of filter wrapper.
That's right.
> Which is correct? If it IS used as an input stream, how does it demarc
> the documents?
Using Content-Length headers. Here is a simple example for indexing e-mail
messages that are stored in a MySQL database. The table is called "ffml"
and has the following fields:
num: This is a unique identifier for each message. Integer.
from_name: e.g. "Philip Mak"
from_email: e.g. "pmak@aaanime.net"
subject: e.g. "Re: [SWISH-E] How does the prog method work?"
message: The body text of the message.
date: A timestamp.
My program does this (using prog and XML):
my $sth = $dbh->prepare(<<"~");
SELECT num, from_name, from_email, subject, message,
UNIX_TIMESTAMP(date) AS date FROM ffml
~
$sth->execute;
while (my $msg = $sth->fetchrow_hashref) {
my $file = "<from_name>".encode($msg->{from_name})."</from_name>\n";
$file .= "<from_email>".encode($msg->{from_email})."</from_email>\n";
$file .= "<subject>".encode($msg->{subject})."</subject>\n";
$file .= "<message>".encode($msg->{message})."</message>\n";
print "Content-Length: ".length($file)."\n";
print "Last-Mtime: ".$msg->{date}."\n";
print "Path-Name: ".$msg->{num}."\n";
print "\n";
print $file;
}
encode() replaces &, < and > with &, < and > respectively.
length() returns the length of the variable, in bytes. By calling length()
and putting the result into a "Content-Length" header, this is how it
demarcates the documents.
Received on Thu Aug 9 23:17:05 2001