try something like this (there are a zillion ways to do it):
you _may_ want to change the line above to:open(FH, ">file.html.bak"); or something just for safety purposes.open (FH, "file.html"); my $find = quotemeta('here.company.com/pagedir'); ## you can use quotemeta like this. my $replace = 'there.company.com'; ## also it is better to define these outside of your loop my $outstring; ## this is a temp variable while (<FH>) { my $string = $_; $string =~ s/$find/$replace/g; $outstring .= $string; ## this concatenates $string to $outstring } close (FH); open (FH, ">file.html"); ## > means open new file for writing print FH $outstring; ## a plain 'print' prints to STDOUT. you want to print to ## your filehandle instead. close (FH);
umm, yes. i hope this explains things. no one yell at me if this is too obtuse.
chiller
In reply to Re: Read from a file and replace
by chiller
in thread Read from a file and replace
by toddler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |