Click to See Complete Forum and Search --> : [RESOLVED] What is wrong with this substitution code..


Mike Burdick
06-01-2007, 11:28 PM
Hi

Sheesh, today is not my day! Everything seems to be going wrong.:confused:

Okay, what is wrong with the following code. It is just a test to see if I understood what was going on. Apparently NOT! :eek:


$text_string="This is an example I would like to solve\n so if it works I'd like to know.\n";
$text_string=~s/\n/^/g;
$text_string=~s/^/zzz/g;
print"\n\n";
print $text_string;


This is what it prints:


zzzThis is an example I would like to solve^ so if it works I'd like to know.^

Charles
06-02-2007, 04:54 AM
Try $text_string = "This is an example I would like to solve\n so if it works I'd like to know.\n";
$text_string =~ s/\n/^/g;
$text_string =~ s/\^/zzz/g;
print "\n$text_string\n";See http://perldoc.perl.org/perlre.html#Regular-Expressions .

Mike Burdick
06-02-2007, 10:52 AM
Ohhhhhhhh:

^ Match the beginning of the line. Yep, it did Exactly as it was told!: :D

Thanks Charles!