Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: replace text using hash

by LanX (Saint)
on Sep 08, 2014 at 18:10 UTC ( [id://1099886]=note: print w/replies, xml ) Need Help??


in reply to Re: replace text using hash
in thread replace text using hash

> 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! :)

update

In 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 ☆☆☆☆ :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1099886]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-04-20 02:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found