Good news, Dan.

That is arguably one of Perl's most famous features!

Regular expresions (Perl's own) are very similar to what you would do with
sed, if you are familiar with that.

open IN,  "< $input"  or die "Unable to open $input for reading, $!,
stopped";
open OUT, "> $output" or die "Unable to open $output for writing, $!,
stopped";

print "Munging $input, creating new file $output.\n";


while ( <IN> ) {
    s/oldtext/newtext/g;  # substitute (replace) oldtext with newtext,
                          # g means globally if happens more than once on a
line.
    print OUT;
}

close IN;
close OUT;

print "Munge complete.\n";

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Dan Anderson
Sent: Friday, December 05, 2003 3:11 PM
To: [EMAIL PROTECTED]
Subject: Replacing text



        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?

Thanks in advance,

-Dan


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to