On 02/05/2014 02:52 PM, Jorge Almeida wrote:
$s="ab";
$s=~s/a/AA/; # $s is now "AAb"


I would like to achieve the same with something similar to the x multiplier:

$n=2;
$s="A"x$n."b"; # $s is "AAb"

$s="ab";
$n=2;
$s=~s/a/Ax$n/; # doesn't work, of course; $s is Ax2b

you need the /e modifier on s///. it allows any perl expression to be used in the replacement part. read http://perldoc.perl.org/perlop.html and look for s/PATTERN/REPLACEMENT/msixpodualgcer and then the section on /e

uri

--
Uri Guttman - The Perl Hunter
The Best Perl Jobs, The Best Perl Hackers
http://PerlHunter.com

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to