in reply to encode files to utf-16 and then move
heh, I bet I wrote that code. One thing I learned since then is that :raw:encoding(...) disables buffering. You want :raw:perlio:encoding(...).
You probably want to specify UTF-16le instead of UTF-16 since you probably want UTF-16le and not UTF-16be.
The snippet is already producing a copy, so all you need to do to make it move is to delete the source once the copy is created.
#!/usr/bin/perl use strict; use warnings; my ($src_qfn, $dst_qfn) = @ARGV; open(my $src_fh, "<:raw:perlio:encoding(UTF-8)", $src_qfn) or die("Can't open \"$src_qfn\": $!\n"); open(my $dst_fh, ">:raw:perlio:encoding(UTF-16le)", $dst_qfn) or die("Can't open \"$src_qfn\": $!\n"); print $dst_fh $_ while <$src_fh>; unlink($src_fh);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: encode files to utf-16 and then move
by tannx (Acolyte) on May 11, 2009 at 13:08 UTC | |
by ikegami (Patriarch) on May 11, 2009 at 14:11 UTC | |
by Anonymous Monk on May 11, 2009 at 13:19 UTC | |
|
Re^2: encode files to utf-16 and then move
by tannx (Acolyte) on May 25, 2009 at 13:04 UTC |