Ted Schuerzinger
wrote, on Thu 12-Jan-06 08:45
: I have a text file with lines like this:
:
: 1 (1) DAVENPORT, LINDSAY 3380.00 16 .00 49.00 USA .00
: 2 (2) CLIJSTERS, KIM 3206.00 17 .00 .00 BEL .00
: [...]
: 28 (28) MOLIK, ALICIA 671.00 15 .00 195.00 AUS .00
: 29 (33) MEDINA GARRIGUES, ANABEL 660.75 27 30.00 10.00 ESP 2.00
: 30 (35) KOUKALOVA, KLARA 660.75 23 16.00 20.00 CZE 2.00
: that I want to turn into a tab-delimited file. Unfortunately, I can't simply
: I have a text file with lines like this:
:
: 1 (1) DAVENPORT, LINDSAY 3380.00 16 .00 49.00 USA .00
: 2 (2) CLIJSTERS, KIM 3206.00 17 .00 .00 BEL .00
: [...]
: 28 (28) MOLIK, ALICIA 671.00 15 .00 195.00 AUS .00
: 29 (33) MEDINA GARRIGUES, ANABEL 660.75 27 30.00 10.00 ESP 2.00
: 30 (35) KOUKALOVA, KLARA 660.75 23 16.00 20.00 CZE 2.00
: that I want to turn into a tab-delimited file. Unfortunately, I can't simply
: turn all
spaces into tabs: note that there are people with two-word surnames.
Part of the problem with this
code
: if ($_
=~/\d\s[A-Z]{3}\s/) {
: $_ = s/$1/$1\t/g;
: }
: $_ = s/$1/$1\t/g;
: }
is you have no capturing parentheses to populate $1. Toss this code.
You seem to have a
pretty good picture of your data; why not turn that into a regex completely,
instead of doing it piecemeal?
/(\d+)\s+\((\d+)\)\s+([A-Z\s]+),\s+([A-Z]+)\s+(\S+)\s+(\S+)\s+(\S+)\s+([A-Z]{3})\s+(\S+)/
and have a replace section
that strings together all your captures with tabs between:
s/.../$1\t$2\t$3\t$4\t$5\t$6\t$7\t$8\t$9\t${10}/
You don't need the
parentheses around field 2, or the comma after the last name, do you? If so, you
can put those inside the captures.
Good
luck,
Joe
==============================================================
Joseph P. Discenza, Sr. Programmer/Analyst
mailto:[EMAIL PROTECTED]
Carleton Inc. http://www.carletoninc.com
574.243.6040 ext. 300 fax: 574.243.6060
Providing Financial Solutions and Compliance for over 30 Years
_______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
