[Chicago-talk] zipcode
Jim Thomason
jthomasoniii at yahoo.com
Fri Feb 27 10:20:19 CST 2004
See? I told you it might need some twiddling.
Naturally, it should be:
substr($data[11], 4, 0, " ")
instead of:
substr($data[11], 4, 1, " ")
(insert AndyRant(tm) about testing your code)
-Jim.....
--- "Dooley, Michael" <Dooley.Michael at con-way.com>
wrote:
> 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";
> }
> }
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at mail.pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
__________________________________
Do you Yahoo!?
Get better spam protection with Yahoo! Mail.
http://antispam.yahoo.com/tools
More information about the Chicago-talk
mailing list