Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Upon execution, the result is:#!/usr/local/bin/perl use strict; use Data::Dumper; my $s = '<img src="http://www.blah.com?one=[KEY]&two=[KEY]"/>'; my $value = '13.95'; my $q_key = quotemeta('[KEY]'); my $q_value = quotemeta($value); $s =~ s/$q_key/$q_value/g; #$s =~ s/\\././g; print Data::Dumper->Dump([$s], [qw/s/]);
Adding in the substitution commented out above yields correct results:$s = '<img src="http://www.blah.com?one=13\\.95&two=13\\.95"/>';
Is there a way to not escape these characters? It seems that my second substitution is merely a hack. Thanks.$s = '<img src="http://www.blah.com?one=13.95&two=13.95"/>';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: variables within substitutions?
by toolic (Bishop) on Jul 05, 2011 at 18:40 UTC | |
|
Re: variables within substitutions?
by jwkrahn (Abbot) on Jul 05, 2011 at 18:50 UTC | |
|
Re: variables within substitutions?
by jethro (Monsignor) on Jul 05, 2011 at 18:41 UTC |