Think about Loose Coupling | |
PerlMonks |
Selectively replacing characters inside a stringby markkawika (Monk) |
on Jun 11, 2009 at 01:01 UTC ( [id://770487]=perlquestion: print w/replies, xml ) | Need Help?? |
markkawika has asked for the wisdom of the Perl Monks concerning the following question:
Hi, Monks! I have a problem that I've come up with a reasonably nice solution for, but have been going over it in my head and wondering if it's the best solution. I have a log file in which I want to hide file and path names. I want to preserve the appearance of a directory structure, so I do not want to hide the "/" characters that are used as directory separators. The filename will always appear at most once per line, and will always appear inside of an easily identifiable section, like this: file="path/goes/here". I would like to process that example so that the output looks like this: file="xxxx/xxxx/xxxx". The solution that I came up with does exactly what I want. From the command line, I pipe it to this (this is on a Unix host): I've been wondering if there is something simpler, like somehow being able to do s|[^/]|x|g on the text between file=" and ", but I haven't been able to figure out how. Does anyone have any suggestions?
Back to
Seekers of Perl Wisdom
|
|