in reply to Re^2: Search and replace within a file
in thread Search and replace within a file
So you're trying to say that $uname doesn't match as a regular expression?
Doesn't using quotemeta change that?
Maybe you want to add case insensitivity (s///i) ?
See How do I post a question effectively? and write this
#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; my $input = 'servername.EXAMPLE.com servername'; my $wantedOutput = 'newname.EXAMPLE.com newname'; my $replacement = 'newname'; my $uname = quotemeta 'servername'; ### dd $input; for( $input ){ s/$uname/$replacement/gi; } dd $input; dd $wantedOutput ; __END__ "servername.EXAMPLE.com servername" "newname.EXAMPLE.com newname" "newname.EXAMPLE.com newname"
As you can see through my use of Data::Dump::dd, it worked, $input has changed and it now looks like $wantedOutput
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Search and replace within a file
by muizelaar (Sexton) on May 08, 2012 at 13:19 UTC |