Nisse Tuta wrote:
Hi all,
Hello,
I'm having a problem solving this one.
I need to replace/substitute a word in a text file.
The problem is that i need to keep the same amount of characters as the
replaced word.
This is for replacing words in a template/postscript file that I use for
printing labels.
After upgrading the OS and CUPS printer driver, things don't work the same.
i.e
In the template text file there is a pattern #------------------# (20
characters).
if I do s/#------------------#/not ok/
it will come out wrong.
If I would substitute with a variable and add spaces for remaining
character not used.
i.e
s/#------------------#/'not ok '/
it works.
I'm hoping that someone could show me how to solve this one.
s/(#------------------#)/ sprintf '%-*s', length( $1 ), 'not ok' /e;
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/