nico7nibor has asked for the wisdom of the Perl Monks concerning the following question:
I have a registry file already decoded in Unicode, I need to replace a value within that file and implement a search and replace...but I keep getting the original file contents instead of the expected result that I am aiming.
$Profile="C:\\registry.reg"; # unicode file $Param="Name"; open (FILE, "<:encoding(UTF-16)", $Profile); @Lines = <FILE>; open FILE, ">$Profile" or die $!; @Lines = <FILE>; close(FILE); foreach $Lines (@Lines) { if ($Lines =~ m/HKEY_LOCAL_MACHINE\\SOFTWARE\\$Param/g) { @LinesSub = split(/\\/,$Lines); $Lines =~ s/$Temp/$Param/g; } print FILE "$Lines"; } close(FILE);
When the file is converted to Ansi manually, the value of the parameter is changed. But I need to make the script do that. I cant seem to change the original (Unicode) file after updating the value from search and replace with the script that i have. It keeps giving me this garbage strings.
I appreciate your help, thanks in advance...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: convert a Unicode file to Ansi, using filehandle..
by CountZero (Bishop) on Nov 06, 2009 at 07:29 UTC | |
|
Re: convert a Unicode file to Ansi, using filehandle..
by markuhs (Scribe) on Nov 06, 2009 at 07:08 UTC | |
|
Re: convert a Unicode file to Ansi, using filehandle..
by ikegami (Patriarch) on Nov 06, 2009 at 16:24 UTC | |
|
Re: convert a Unicode file to Ansi, using filehandle..
by nico7nibor (Novice) on Nov 06, 2009 at 08:52 UTC | |
by wfsp (Abbot) on Nov 06, 2009 at 12:03 UTC | |
|
Re: convert a Unicode file to Ansi, using filehandle..
by nico7nibor (Novice) on Nov 11, 2009 at 02:59 UTC |