Book Home Programming PerlSearch this book

31.15. use open

use open IN => ":crlf", OUT => ":raw";

The open pragma declares one or more default disciplines for I/O operations. Any open and readpipe (that is, qx// or backticks) operators found within the lexical scope of this pragma that do not specify their own disciplines will use the declared defaults. Neither open with an explicit set of disciplines, nor sysopen under any cirumstances, is influenced by this pragma.

Only the two disciplines :raw and :crlf are currently available (though as of this writing we expect a :utf8 discipline to be along shortly). On legacy systems that distinguish between those two translation modes when opening files, the :raw discipline corresponds to "binary mode", and :crlf to "text mode". (These two disciplines are currently no-ops on platforms where binmode is a no-op, but only for now; see the open function in Chapter 29, "Functions", for a longer description of the semantics we expect of various disciplines.)

Full-fledged support for I/O disciplines is currently unimplemented. When they are eventually supported, this pragma will serve as one of the interfaces to declare default disciplines for all I/O. At that time, any default disciplines declared by this pragma will be available by the special discipline name ":DEFAULT" and usable within handle constructors that allow disciplines to be specified. This will make it possible to stack new disciplines over the default ones.

open (FH, "<:para :DEFAULT", $file) or die "can't open $file: $!";
Once complete, full support for I/O disciplines will enable all supported disciplines to work on all platforms.



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.