If you want tab instead of space after each country code, try this:
while (<FILEFROM>) {
if (/\d\s[A-Z]{3}\s/) {
s/(\d\s[A-Z]{3})\s/$1\t/g;
}
print FILETO $_;
}
>
> I'm fairly good at using regexes to find things, but using them to
> *replace* things is something I find quite difficult. I have a text file
> with lines like this:
>
> <snip>
>
> 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
>
> </snip>
>
> 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. However, I'm having difficulty coming up with any ideas on how
> to find information on either side of a space, and changing that into
> something plus a tab. I tried the following to deal with the country
> codes:
>
> while (<FILEFROM>) {
> chomp;
> if ($_ =~/\d\s[A-Z]{3}\s/) {
> $_ = s/$1/$1\t/g;
> }
> print FILETO "$_\n";
> }
>
> But all I got was a file with a bunch of lines of 1's. I tried escaping
> the $'s, figuring it wouldn't help, and it didn't: I ended up with an
> empty file. I also tried putting () around each of the $'s, and that gave
> me an even odder file, with each line containing a two-digit number, with
> no relationship I can spot between the numbers and the country codes: USA
> produces 54, 51, and 52 the first three times it's matched, while RUS
> produces 50, 54, 54, and 56 the first four times it's matched.
>
> I've tried reading perlre, and it's given me no help. I don't know where
> to begin.
>
> --
> Ted Schuerzinger, [EMAIL PROTECTED]
>
> _______________________________________________
> Perl-Win32-Users mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs