Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: How do I avoid double substitution when replacing many patterns?

by barbie (Deacon)
on Jan 26, 2007 at 15:55 UTC ( #596737=note: print w/replies, xml ) Need Help??

in reply to How do I avoid double substitution when replacing many patterns?

You might want to take a look at Data::Phrasebook, as this handles things a little better. Using your example the following works:

use Data::Phrasebook; my $pb = Data::Phrasebook->new( file => 'phrases.txt' ); my $str = $pb->fetch( 'baz', {foo => '${bar}', bar => '${foo}'} ); # $str = 'foo is ${bar} and bar is ${foo}'

where phrases.txt use the default parameter substitution and looks like:

baz=foo is :foo and bar is :bar

While there is support for TT style parameter substitution, it doesn't current support a TT embeded templating system. Might be a possibility for the future, but would be a little overkill for this problem ;)

Barbie | Birmingham Perl Mongers user group |

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://596737]
belg4mit kicks Perl in the shins, "Unmatched ) in regex; marked by" my ass
[belg4mit]: Nothing wrong with perl -le 'print ":)" =~ /(?^u:^(\:|\:\))$) /'
[Lotus1]: belg4mit are you on a Linix server?
[belg4mit]: yes. the regular expression is generated in code from a text file. that s the regular expression that Perl blows up when it reaches it, but if I use it from the comman line it's fine
[belg4mit]: oh, wait, damn, different lne number

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-04-25 16:40 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (459 votes). Check out past polls.