Zielinski Daniel wrote at Mon, 23 Sep 2002 13:53:54 +0200:

> Got following problem:
> 
> Want to substitute roman digits (I...) with arabic(1...):
> 
> $corr_line="<Band>Vol. I, parte speciale" (example, position of I may
> vary)
> $corr_line=~s/(>| |,|;)I( |,|;|:|\n)/$11$2/;
> 
> I think that I have to interpolate the variables but don't know how.
> Can anybody give me a hint?

If I understand you correctly,
you want to substitite character looking like roman digits
to arabic ones.
The looking like depends also on some character before and
after the digits.

First, let's group the characters surrounding these digits
with character classes:
before are     [> ,;] (perhaps it's better to say [>\s,;])
after could be [: ,;\n] (perhaps it's better to say [:\s,;])

That would yield a substituation like
(with the trick of lookahead and lookbehind assertions,
 look perldoc perlre for details):

$corr_line =~ s/(?<=[> ,;])I(?=[:\s,;])/1/;


In a more generalized way,
I would suggest to use existing modules for conversions,
e.g. the CPAN-module roman:

use Roman;
$corr_line =~ s{(?<=[> ,;])([IVXCLM]+)(?=[: ,;\n])}
               {isroman($1) ? arabic($1) : $1}ge;


Best Wishes,
Janek


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to