CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [Anglachel] replacement with exact number of chars: Edit Log



Zhris
User

Dec 5, 2010, 1:34 PM


Views: 4689
Re: [Anglachel] replacement with exact number of chars

I think it would be best if you used the substr function instead of a regular expression:


Code
#!/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)


Edit Log:
Post edited by Zhris (User) on Dec 5, 2010, 1:35 PM
Post edited by Zhris (User) on Dec 5, 2010, 1:36 PM
Post edited by Zhris (User) on Dec 5, 2010, 1:37 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives