Mega Code Archive

 
Categories / Perl / String
 

Replace function based on substr function

sub replace {     ($text, $to_replace, $replace_with) = @_;     substr ($text, index($text, $to_replace),         length($to_replace), $replace_with);     return $text; } print replace("Here is the text.", "text", "word");