On Mon, May 11, 2009 at 04:50, Jenda Krynicky <je...@krynicky.cz> wrote: > From: Raymond Wan <rwan.w...@gmail.com> >> On Fri, May 8, 2009 at 8:58 PM, John W. Krahn <jwkr...@shaw.ca> wrote: >> >> > >> > That depends on the operating system you are using. I use Linux so there >> > is no difference between "binary" and "text", except for those specific >> > applications that can't handle "binary" data. If you are on a system like >> > DOS/Windows then reading or writing "binary" data as "text" will cause >> > problems because line ending translation occurs with "text" files but not >> > with "binary" files. >> >> I'm on a Linux system too; I guess I've used it for so long, I forgot about >> the situations when binary/text does matter (i.e., Windows). I see...so it >> doesn't matter. That would make sense since I just pipe to stdout right >> now and whether I'm sending "text" [ie., human-readable characters] or not, >> it all seems to work fine... > > Well ... it seems, but it doesn't have to. Based on the locale > settings, if you do not binmode() the filehandle or open it with the > right IO layer specified, the stuff you print may undergo some > charset conversions. > > perldoc -f binmode says > > On some systems (in general, DOS and Windows-based systems) binmode() > is necessary when you're not working with a text file. For the sake > of portability it is a good idea to always use it when appropriate, > and to never use it when it isn't appropriate. Also, people can set > their I/O to be by default UTF-8 encoded Unicode, not bytes. > > In other words: regardless of platform, use binmode() on binary data, > like for example images. snip
or the more modern: open my $fh, ">:raw", $filename or die "could not open $filename: $!"; from perldoc perlio[1] The :raw layer is defined as being identical to calling binmode($fh) - the stream is made suitable for passing binary data i.e. each byte is passed as-is. The stream will still be buffered. 1. http://perldoc.perl.org/PerlIO.html -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/