go ahead... be a heretic | |
PerlMonks |
Re^2: replace text using hashby LanX (Saint) |
on Sep 08, 2014 at 18:10 UTC ( [id://1099886]=note: print w/replies, xml ) | Need Help?? |
> modify the regex to treat whitespace agnostically, and then replicate the type of whitespace in your result. OK I missed that part. But I think substituting each blank with a grouped (\s) should do. Like this the positions of each whitespace match is known and can be mapped back to blank before doing the hash look-up. Evidently using any whitespace different to blank must be forbidden in the keys. And at this point it gets obvious that looking at CPAN for a ready to use module should be a good idea! :)
updateIn hindsight thats BS. This kind of translation with different length expressions can't reproduce good formatting. It's better to hold each paragraph in one line in a normalized form, where each non-blank whitespace is eliminated and to do the formatting again after substitution .
Cheers Rolf (addicted to the Perl Programming Language and ☆☆☆☆ :)
In Section
Seekers of Perl Wisdom
|
|