cre8tor has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I'm new here and must confess my perl knowledge is very limited. I'm trying to use a perl script that will replace a line in an other html file on the same box. Problem is that there are brackets ( ) in the text that I want to replace and I can't find a way to get it to work. Here is my code:
my $filename = '/tmp/somefile.html'; my $find = "<option SELECTED>[ Current time range ]"; my $replace = '<option SELECTED> Current time'; { local @ARGV = ($filename); local $^I = '.bac'; while( <> ){ if( s/$find/$replace/ig ) { print; } else { print; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to replace a piece of text containing brackets in an external file
by LanX (Saint) on Dec 15, 2012 at 21:19 UTC | |
by cre8tor (Initiate) on Dec 16, 2012 at 07:22 UTC | |
|
Re: How to replace a piece of text containing brackets in an external file
by tobyink (Canon) on Dec 15, 2012 at 21:28 UTC | |
|
Re: How to replace a piece of text containing brackets in an external file
by Anonymous Monk on Dec 16, 2012 at 01:00 UTC |