Stephen Gran on 22 Dec 2004 03:59:58 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

regex/printf question


Hello all,

This may be basic, but I am going to ask it anyway.

I have a string, destined for output.  This string contains markers that
are s/// replaced before output, and life is good.  The only problem, is
that I would like to preprocess the print lines a little, and I have no
idea how.

Say I have the string:

On %marker1% at %marker2%, something happened %COUNT_marker1% times

It's trivial to s/\%marker\%/real_values/ as I go, and get a reasonable
output.  What I'd like to do is turn %COUNT_marker1% into the equivalent
of 'printf "%8d", $count;'  This should only occur on the counter, not
on every string.

%marker1%, %marker2% and %COUNT_marker1% are counted in the script, and
the data is correct.  The problem is the pretty-printing, so to speak.
Part of the problem is that I don't always know programmatically whether
I am examining a string or a count.  I could take extra care to find out,
but I'd be interested in a more general solution, if one is available.

So, can I say:

my $tmp_msg = $string_with_markers
$tmp_msg =~ s/\%COUNT-foo\%/%8, $count/

I know that I can't directly, but have people run across this before and
have a canned solution?

Thanks a lot,
-- 
 --------------------------------------------------------------------------
|  Stephen Gran                  |  "And what will you do when you grow up |
|  steve@lobefin.net             | to be as big as me?" asked the father   |
|  http://www.lobefin.net/~steve | of his little son.  "Diet."             |
 --------------------------------------------------------------------------

Attachment: pgplYI4xQkmLm.pgp
Description: PGP signature