On 10/31/2006 10:20 AM, C.R. 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, becasue 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. 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/.



Did you try the code that Rob Dixon posted? It works for me with your longer example string.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to