The following need to be edited: (Click on the hyperlinked lines to see editing comments)


#!/usr/bin/perl5
require 'cgi-lib.pl';
$indata="your_file.txt";
$header="your_header_file.htm";
open (DATA, $indata) || &CgiError("Unable to open database for reading $indata");
my (%data, @names, $hash, $line, $data, @printed, $temp, $blarg);
umask (011);
while (<DATA>) {
		chop $_;
		#Below is the record split character, in this case, the pipe: |
		#Change this to reflect your split character. See the README for details
		my @line = split /\|/;
		# The next line dictates the sort order. See the README for details.
		my $blarg = "$line[1]$line[0]";
		#These are the fields in the order they appear in your datafile.
	        @{$data{$blarg}}{qw(
	                fname lname title company address1 address2
	                city province postal country work_phone
	                work_fax email
	         )} = @line;  
		push @names, $blarg;
}
#This  foreach loop assigns each name to an array appropriate to it's starting character
foreach (@names) {
	$temp=(substr $_, 0, 1);
	$temp=~ tr/A-Z/a-z/;
	push @$temp, $_;
}
# This foreach loop deletes your old files before updating
foreach ('a'..'z') {
	unlink "../members/$_".".htm";
}
# This foreach loop and suproutine opens your files to be written and writes the HTML header info
foreach ('a'..'z') {
	$writefile = "../members/$_.htm";
	open (WPUBLISH, ">>$writefile") || die "Couldnt open ";
	&WRITEHEADER;
}
# This loop opens each file again and adds the individual, sorted records.
foreach ('a'..'z') {
	$writefile = "../members/$_.htm";
	open (WPUBLISH, ">>$writefile") || die "Couldnt open ";
	foreach (@$_) {
print WPUBLISH<<EOF;
<TR><TD><B>First Name</TD><TD>$data{$_}{fname}</TD></TR>
<TR><TD><B>Last Name</TD><TD><B>$data{$_}{lname}</B></TD></TR>
<TR><TD><B>Title</TD><TD>$data{$_}{title}</TD></TR>
<TR><TD><B>Company</TD><TD>$data{$_}{company}</TD></TR>
<TR><TD><B>Address 1</TD><TD>$data{$_}{address1}</TD></TR>
<TR><TD><B>Address2</TD><TD>$data{$_}{address2}</TD></TR>
<TR><TD><B>City</TD><TD>$data{$_}{city}</TD></TR>
<TR><TD><B>Province</TD><TD>$data{$_}{province}</TD></TR>
<TR><TD><B>Postal Code</TD><TD>$data{$_}{postal}</TD></TR>
<TR><TD><B>Country</TD><TD>$data{$_}{country}</TD></TR>
<TR><TD><B>Phone</TD><TD>$data{$_}{work_phone}</TD></TR>
<TR><TD><B>Fax</TD><TD>$data{$_}{work_fax}</TD></TR>
<TR><TD><B>Email</TD><TD><A HREF=\"mailto:$data{$_}{email}\">$data{$_}{email}</A></TD></TR>
<TR><TD> </TD></TR>
EOF
	}
	print WPUBLISH "</TABLE></TABLE>\n</BODY>\n<</HTML>";
}
print &PrintHeader;
print "Done!\n";

sub WRITEHEADER {
	open (PGHEAD, $header) || &CgiError("Unable to open $header for reading");
  	while (<PGHEAD>) {
  		print WPUBLISH $_;
  	}
  }

  1. Path to PERL

  2. CGI-LIB is included in the multipass archive. (Yes, I know, I should be using CGI.PM, I've just been too lazy to read up on it. Feel free to modify the script to make use of it)

  3. The path to your data.txt file. A sample your_file.txt format is included in membermanager.zip

  4. The path to your html header file. This is the file you would include to have your nav bar, logos, body attributes, etc, in each created file.

  5. This is your 'split' character, the character used to separate fields from your exported database. Be careful not to use a character that can be contained within fields, or it will foul up the recorde order. For example, if you used a comma as your split field, but had a record such as Bissonnette, MD, BAsc, this would split into three fields, when only one was intended.

    Generally, it is advised to leave this as the pipe character. Most databases allow you to specify your own split character.

  6. This line dictates your sort order. Actually, it creates the hash names, but that's what's being sorted. Remember that in Perl, the first record of an array is 0. So if you wanted to sort on the person's last name, which was in the second field of each line, the sort field would be $line[1] (since the first field is 0). This is combined with the first name ($line[0]) to reduce mixups with identical last names. If you really want to ensure no mixups (incase you have many John Doe's in your database), the second half of this could be the phone number or email address.

    So, to use the code from above, if you wanted to sort by last name, and ensure no record duplication by combining last name wiht the phone number, the line would read: my $blarg = "$line[1]$line[10]";

  7. The records, as they appear in your exported databse. Make sure whatever record names you change are also matched in the print records below this line (the table stuff)

Copyright

This script is being distributed as shareware. If you like it, if it saves you time and money, and more importantly, if you continue to use it, please feel send $50 to the address in the comments section of membermanager.cgi (Don't need spam bots grabbing the address from here)


Back to MemberManager page