
Zhris
Enthusiast
Dec 5, 2010, 1:34 PM
Post #2 of 4
(9331 views)
|
Re: [Anglachel] replacement with exact number of chars
[In reply to]
|
Can't Post
|
|
I think it would be best if you used the substr function instead of a regular expression:
#!/usr/bin/perl use strict; use warnings; my $string = 'AAAABBBBCCCC'; print "$string\n"; my $replace_char = 'X'; my $replace_start = "4"; my $replace_end = "8"; my $replace_range = $replace_end - $replace_start; my $replace_string; for (1 .. $replace_range) { $replace_string .= $replace_char; } substr ($string, $replace_start, $replace_range) = $replace_string; print "$string\n"; Chris
(This post was edited by Zhris on Dec 5, 2010, 1:37 PM)
|