===== Or, to make it even simpler, how do I get this snippet to print out a copy of the config file:$filesenders = "z:/train/whitesenders.txt"; $fileaddrlist = "z:/Program Files/Mailsweeper for SMTP/Config/shared/a +ddrlist.test"; #Read and arrayify list of SMTP addresses open SENDERSREAD, $filesenders or die "unable to open sender file" ; foreach $newsender (<SENDERSREAD>) { chomp $newsender; push @senders, $newsender; } #Open MailSweeper Addrlist.cfg and pull address lists into a hash of a +rrays open (CONFIGREAD, "<:utf8", $fileaddrlist) or die "UNable to open conf +ig file for read"; print "Reading Config File...\n"; foreach (<CONFIGREAD>) { chomp; if (/\[(.*)\]/) { $currhead = $1; print "$currhead\n"; next; } next if (!(/./)); #Check for and omit blank lines push @{$config{$currhead}}, $_; } close CONFIGREAD; #Put senders captured from file into appropriate list foreach (@senders) { push @{$config{'AddressList\Scripted Whitelist'}}, "v:Member=\$S\"$_ +\""; } #write updated config to file, overwriting existing file open (CONFIGWRITE, ">:encoding(UTF-8)", $fileaddrlist) or die "unable +to open config file for write"; foreach (keys %config) { print CONFIGWRITE "[$_]\n"; foreach (@{$config{$_}}) { print CONFIGWRITE $_; print CONFIGWRITE "\n"; } print CONFIGWRITE "\n"; } close CONFIGWRITE;
If requested, I can make a sample of the source file available. ===== OK, further work, further progress. I've finally determined that if I read the file in with UTF-16LE encoding, I get the strings in usable form. But if I output the fule using :encoding(UTF-16LE) I'm back to having a space between every character. Is this because Perl uses UTF-8 internally? If so, do I maybe have to use Unicode::String to convert the strings before sending them back to the filehandle?open (READ, "z:/test.txt") or die "unable to open file"; foreach (<READ>) { push @array, $_; } foreach (@array) { print $_; }
In reply to Reading and writing to unicode files by cbingel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |