Chuck Roberts wrote:
>
> In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] says...
>>
>> You need to show us your code Chuck. Perl doesn't do that, in any situation
>> that I can think of. Try running this on its own:
>>
>> my $s = '144 cm';
>> $s =~ s/(\d+ +cm)/<bx;1>$1<ba>/g;
>> print $s;
>>
>> I get
>>
>> <bx;1>144 cm<ba>
>>
>> what do you get?
>>
>> That may help on its own. If not, like I said, post the relevant part of your
>> code.
>
> Your example above is extremely simple, and simply does not apply to my
> situation. But yes, that code above will work on my version of Perl,
> because Perl is only replacing one instance of /\d+ cm/. My situation is
> more complicated where I need to replace MULTIPLE instances of /\d+ cm/
> in a single string.
Sure, but my intention was to reproduce what you were seeing, and you posted
this:
Chuck Roberts wrote:
>>>
>>> Well, that kinda worked. I had to change it to work on a scalar so this
>>> is what I wrote:
>>>
>>> $s=~s/(\d+ +cm)/<bx;1>$1<ba>/g;
>>>
>>> Input string: 144 cm
>>> Output string: <bx;1>14<bx;1>4 cm<ba><ba>
So I coded exactly that (except that I replaced the unlimited spaces with
unlimited whitespace) and got a different result.
> My first post in this thread shows example data as it is stored in a
> scalar variable. It also shows what the string SHOULD look like after
> the substitution.
>
> Or maybe, perl simply is not able to replace multiple instances of a
> regex expression in a single scalar/string variable.
>
> $s="54 x 34 x 30-3/4 H<l>137 x 86 x 78 cm<l>Kneehole Height: 24-1/2``
> (62 cm)<l>Chair height: 30-3/4 (78 cm)<l>";
>
> (Don't worry about special strings like <l>, they are used by our
> typesetting software.) Notice that 78 cm appears twice, both should
> have <bx;1><ba> around them.
>
> $s should end up like this:
> 54 x 34 x 30-3/4 H<l>137 x 86 x <bx;1>78 cm<ba><l>Kneehole Height:
> 24-1/2`` (<bx;1>62 cm<ba>)<l>Chair height: 30-3/4 (<bx;1>78 cm<ba>)<l>
>
> Notice the insertion of <bx;1> and <ba> around strings that match
> /\d+ cm/.
Fine. Lets try again:
my $s="54 x 34 x 30-3/4 H<l>137 x 86 x 78 cm<l>Kneehole Height: 24-1/2`` (62
cm)<l>Chair height: 30-3/4 (78 cm)<l>";
$s =~ s/(\d+\s+cm)/<bx;1>$1<ba>/g;
print $s, "\n";
**OUTPUT**
54 x 34 x 30-3/4 H<l>137 x 86 x <bx;1>78 cm<ba><l>Kneehole Height: 24-1/2``
(<bx;1>62 cm<ba>)<l>Chair height: 30-3/4 (<bx;1>78 cm<ba>)<l>
which is exactly what I expected and exactly what you say you want, but somehow
it's not what you're getting. Something else is happening somewhere and we can't
be sure what it is unless you show us your code as I asked.
But I can try to guess. It does look very much to me as if you're trying to make
the substitution twice, using two different methods. Look:
my $s = '144 cm';
$s =~ s/(\d+\s+cm)/<bx;1>$1<ba>/g;
$s =~ s/(\d +cm)/<bx;1>$1<ba>/g;
print $s, "\n";
**OUTPUT**
<bx;1>14<bx;1>4 cm<ba><ba>
Which is exactly what you're seeing. Check your code for something like that.
And if I'm wrong, then please post your code.
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>