Dan Anderson wrote: > > I have a script that reads text from a file and inserts text > into different places depending on what it needs to do. But I use > split to replace the text, i.e.: > > ($first_part, $second_part) = split "#INSERT#TEXT#HERE#", $document, 2; > print FILEHANDLE $firstpart, $text_to_insert, $secondpart; > > Is there a replace function in perl that would let me do > something like replace "#INSERT#TEXT#HERE", $text_to_insert;? I was > going to write my own method but was curious if perl had something > faster?
You could use the substitution operator: $document =~ s/#INSERT#TEXT#HERE#/$text_to_insert/; Or you could use a combination of substr(), index() and length(): my $text_to_find = '#INSERT#TEXT#HERE#'; substr $document, index( $document, $text_to_find ), length $text_to_find, $text_to_insert; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>