#!/usr/bin/perl -wl # # Tom Moertel # 12 April 2002 # # $Id: postnet.pl,v 1.3 2003/11/05 02:49:14 thor Exp $ my $opt_tex = shift if @ARGV && $ARGV[0] =~ /-?-(la)?tex/i; my $opt_dig = shift if @ARGV && $ARGV[0] =~ /-?-digits/i; my @lookup = qw(||... ...|| ..|.| ..||. .|..| .|.|. .||.. |...| |..|. |.|..); my ($shortbar, $longbar) = qw({\rule{0.020in}{0.050in}\hspace{0.0258in}} {\rule{0.020in}{0.125in}\hspace{0.0258in}}); foreach (@ARGV) { tr/0-9//cd; my @digits = split //; my $negsum = 0; $negsum -= $_ foreach @digits; push @digits, $negsum % 10; my $barcode = $opt_dig ? join(" ", @digits) : join("", "|", (map {(@lookup)[$_]} @digits), "|"); if ($opt_tex) { $barcode =~ s/(.)/$1 eq "." ? $shortbar : $longbar/eg; } print $barcode; } =head1 NAME postnet.pl - Generate POSTNET bar codes =head1 SYNOPSIS B [B<--digits>|B<--latex>] I ... =head1 DESCRIPTION Generates US Postal Service POSTNET bar codes for the ZIP and ZIP+4 codes given on the command line, one bar code per line of output. (Actually, this program will generate bar codes for any number of decimal digits. In particular, if you know the delivery-point code, you can append it to your ZIP+4 to generate a full delivery-point bar code.) =head1 OPTIONS The B<--latex> option causes the program to emit LaTeX instructions that draw the bar code per US postal specifications. Otherwise, the program will emit an ASCII approximation of the bar code. The B<--digits> option causes the program to print out the decimal digits that underly the bar code. It is useful for examining the final digit, which is the check digit. =head1 CAVEATS Only the LaTeX output is suitable for use in actual mailings. The ASCII approximation is not acceptable to the US Postal Service and is intended only for human inspection. =head1 SEE ALSO US Postal publication 25, Chapter 4, "POSTNET Barcodes" http://pe.usps.gov/text/Pub25/Pub25ch4.htm =head1 AUTHOR Tom Moertel 2002-04-12