@rem = '--*-Perl-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
:WinNT
perl -x -S %0 %*
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
#!/bin/perl -w
#line 15

#	This makes use of the nice flatfile addressbook program to be found
#	at http://www.red.roses.de/~clemens/addressbook/
#	or
#	http://addressbook.home.pages.de/ 

#	Open addressbook, select subset, and print

use PostScript::MailLabels 2.0;
use AddressBook;

$labels = PostScript::MailLabels->new;

#	Open address book and select addresses to print

my $book = "$ENV{HOME}/addresses_private";

my $addr = AddressBook->new($book);

my $data = $addr->getaddresses('Xmas list','Yes');

#	Prepare mailing labels (assume you've already calibrated them)

	$labels->labelsetup( Units => 'english',
	                    Font => 'Helvetica',
						Printable_Left		=> 0.25,
						Printable_Right		=> 0.25,
						Printable_Top		=> 0.0,
						Printable_Bot		=> 0.55,
						
						Output_Top		=> 0.5, 
						Output_Width	=> 2.625, 
						Output_Height	=> 1.0, 
						X_Gap			=> 0.16,
						Y_Gap			=> 0.0,
						Number			=> 30,

						#	Adjustments for printer idiosyncracies

						X_Adjust		=> 0.05,
						Y_Adjust		=> 0.05,

	                   );

my @addresses; 
# address array elements are : first, last, street_addr, city, state, zip

#	Build array of addresses
foreach (sort {$a->[1] cmp $b->[1]} @{$data}) {
	if ($_->[3]) {
		push @addresses,[$_->[0],$_->[1],$_->[3],$_->[5],$_->[6],$_->[7]];
	}
	else {
		push @addresses,[$_->[0],$_->[1],$_->[4],$_->[5],$_->[6],$_->[7]];
	}
}

#	Create labels

my $output = $labels->makelabels(\@addresses);

open (UT,">labels_out.ps") || die "Warning, cannot write labels_out.ps, $!\n";
print UT $output;
close UT;

print "\n******** View labels_out.ps with ghostscript ********\n";

__END__
:endofperl
