Jim Magnuson wrote:
>
> On Jan 10, 2007, at 10:44 AM, John W. Krahn wrote:
>
>> Jim Magnuson wrote:
>>
>>> For purposes of doing some processing on a Finnish corpus, I want to
>>> convert repeated vowel strings to a single occurrence of the uppercase
>>> form of the vowel. That is:
>>>
>>> "aa" -> "A"
>>> "ii" -> "I"
>>> "oo" -> "O"
>>>
>>> Is it possible to do this without specifying separate substitutions
>>> for
>>> each vowel?
>>
>> You could do it something like this:
>>
>> my %convert = (
>> aa => 'A',
>> ii => 'I',
>> oo => 'O',
>> );
>>
>> $corpus =~ s/(aa|ii|oo)/$convert{$1}/g;
>
> Can I impose on you a little more? Your solution seems to remove the
> matched string w/o substitution:
>
> perldl> p %convert
> qq Q ii I uu U oo O yy Y aa A ww W ee E
>
> perldl> $x="aabcdee"
>
> perldl> $x=~s/aa/$convert{$1}/g
>
> perldl> p $x
> bcdee
>
> If you can advise me on how to repair this, I'd be grateful. Thanks
> very much for your help,
You will notice that in my example there are capturing parentheses which store
the captured string to the $1 variable but in your example there are no
capturing parentheses so the $1 variable contains nothing.
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/