perl-unicode

Establishing IO code conventions

2010-04-09 11:38:30
The `open` pragma allows you to set default values for two-argument calls to 
open and some other operators for a lexical scope, for example file level. 
Where you need something else you can call binmode or three-argument open or 
use the `open` pragma in a narrow lexical scope.

Supposed you have (a) a mixture of text and binary data to read and write, (b) 
a requirement to produce all text output as Unicode/UTF-8, (c) the usual 
mixture of hundreds of *.pl and *.pm forming an application or convention 
domain, and (d) only medium programmer awareness of the text/byte problem, what 
do you think is the best policy to set?

Of course, educate people on what to use and what not to use.

But apart from that, would you:

use open qw/:utf :std/;                  # as a default
binmode $fh;                             # where required
binmode, open, use open ':encoding(xy)'; # where required

Would you do that:

* in every file
* only in *.pl
* only where IO happens
* only in narrow lexical scopes
* no convention

The best would probably be to restrict IO to a certain set of files, and leave 
the rest pure (with text for text and binary for binary), but unfortunately 
that's not immediately possible.

Thanks for any advice you might have to share.
-- 
Michael.Ludwig (#) XING.com

<Prev in Thread] Current Thread [Next in Thread>
  • Establishing IO code conventions, Michael Ludwig <=