[Chicago-talk] zipcode

Dooley, Michael Dooley.Michael at con-way.com
Fri Feb 27 10:01:57 CST 2004


ok if you have a CSV file that has 12+ fields.
on the 12th field you have a zipcode. if the Zip is 7 character put a space
between the 4th and 5th character.

I don't know why I am having this brain blockage but:

1) is there a better way to do the regex below?
2) how do I do the inline edit?

what I have below works but I know there has to be a much better way to edit
the zipcode.

#!/usr/bin/perl -w

use strict;

while (<> ) {
if (/(\w*,\w*,\w*,\w*,\w*,\w*,\w*,\w*,\w*,\w*,\w*,)(\w*)(.*)/) {
        if (length($2) == 7) {
                my $zipstart=substr($2,0,4);
                my $zipend=substr($2,4,3);
                print "$1$zipstart $zipend$3\n";
                next;
        }

        print "$1$2$3\n";
}
}



More information about the Chicago-talk mailing list