[ic] fedex file conversion

Mike Heins mike at perusion.com
Fri Dec 19 17:25:24 EST 2003


Quoting Nathan Barnett (nbarnett at specialty-books.com):
> Is there a script out there to convert the FedEx ascii rate and zone
> files to an IC readable format?
> 
> http://www.fedex.com/us/rates_new/downloads/?link=4
> 

As far as I knew, there were no ASCII zone files before now --
you had to get their PDF and clip and paste.

It is good to know these exist. I might format them up and make
them available.

I have a script which makes the rate files good:

#!/usr/bin/perl

## Turns N-N column into separate columns.
##
##  usage: joindash < input > output
##
## Used for building Fedex rate tables from their brain-dead thing


use Getopt::Std;

getopts('td:j:');

use vars qw/$opt_t $opt_d $opt_j/;
use strict;
my $delim =  $opt_t ? "\t" : '\s*,\s*';
my $joiner = $opt_t ? "\t" : ',';

$delim = $opt_d if $opt_d;
$joiner = $opt_j if $opt_j;

my @cols;
my @ocols;
my @hcols = 'weight';

$ocols[0] = 0;

while(<>) {
	next unless /^Weight/i;
warn "Found weight line\n";
	s/Zone //g;
	s{/}{-}g;
	@cols = split /\s*,\s*/, $_;
	for (my $i = 1; $i < @cols; $i++) {
		$cols[$i] =~ m{(\d+)(?:-(\d+))?};
		my $b = $1;
		my $e = $2;
warn "i=$i b=$b e=$e";
		if($e) {
			for ( my $j = $b; $j <= $e; $j++ ) {
				$ocols[$j] = $i;
			}
		}
		else {
			$ocols[$b] = $i;
		}
	}
	last;
}

for(my $i = 1; $i < @ocols; $i++) {
	next unless defined $ocols[$i];
	push @hcols, $i;
}
print join $joiner, @hcols;
print "\n";

while(<>) {
	if(/^(FedEx.*Envel|Letter)/i) {
warn "Found fedex envelope line\n";
		s/.*?,/Letter,/;
	}
	else {
		last unless /^\d+/;
	}

	s/\s+$//;
	s/\$//g;
	my @f = split /$delim/o, $_;
	my @out;
	for( my $i = 0; $i < @ocols; $i++) {
		next unless defined $ocols[$i];
		push @out, $f[$ocols[$i]];
	}
	print join $joiner, @out;
	print "\n";
}

### END SCRIPT

The zone tables I have never looked at, but if I have time between Christmas
and New Year I might look at them.

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.647.1295      <mike at perusion.com>

Software axiom: Lack of speed kills.


More information about the interchange-users mailing list