On Tuesday, September 9, 2003, at 08:58 PM, perlwannabe wrote:<SNIP, SNIP>
I know it involves using the s/// operator to both strip the tabs and replace with <sp> but the problem is that it requires using an array for each address...and that is what is creating problems for me.
Thanks...
Hmm, let me think out loud a little.
I think I see a pattern, so let's first change all of them to spaces. That's easy enough:
s/\t/ /g;
Now, if we switch all the spaces that are supposed to be tabs to tabs, we're done, right. I bet we can handle that. What about:
s/ ([A-Za-z]:) /\t$1\t/g; # and... s/^([A-Za-z]:) /$1\t/; # The first one is a special case
# or, most complex...
s/(^| )([A-Za-z]:) / length($1) ? "\t$1\t" : "$1\t" /eg;
You may have to adjust it a little if any of my assumptions are wrong, but it should be close to what you need, I think. Does that help any?
Yes, but the problem is that there is a mix of numbers and letters in the
address. There is a response to the list that was right on the money.
But, your example definitely put me on the right track in dealing with a
more complex s/// operator. Thanks!
I know you already have your solution, but I thought I would cover this anyway. It was late last night when I responded and I was obviously fully of mistakes. Here's the corrected code:
tr/\t/ /; s/(^| )([A-Za-z]+:) / length($1) ? "\t$2\t" : "$2\t" /eg;
This does work on all the sample lines you provided.
You mentioned the numbers in the addresses, but that doesn't affect what I was going for here. Here's how it works:
First, we just convert all tabs to spaces. Simple.
Then, what we need is to change only the spaces that should be tabs. Those spaces are on either side of Address:, City:, and State:, so in our search we just look for one or more letters with a colon at the end, surrounded by spaces. Then we replace those spaces with tabs. The search is slightly more complex than that only because it handles the special case of Address: at the beginning of the line, which won't have a space in front of it.
Sorry for all the errors.
James
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]