RE: Two questions
[p5sagit/p5-mst-13.2.git] / lib / open.pm
index 6be8b97..b535d88 100644 (file)
@@ -10,13 +10,14 @@ sub in_locale { $^H & $locale::hint_bits }
 
 sub _get_locale_encoding {
     unless (defined $locale_encoding) {
+       # I18N::Langinfo isn't available everywhere
        eval {
-           # I18N::Langinfo isn't available everywhere
            require I18N::Langinfo;
-           I18N::Langinfo->import('langinfo', 'CODESET');
+           I18N::Langinfo->import(qw(langinfo CODESET));
+           $locale_encoding = langinfo(CODESET());
        };
        unless ($@) {
-           $locale_encoding = langinfo(CODESET());
+           print "# locale_encoding = $locale_encoding\n";
        }
        my $country_language;
         if (not $locale_encoding && in_locale()) {
@@ -65,7 +66,7 @@ sub import {
            $type = 'IO';
            $dscp = ":$1";
        } else {
-           $dscp = shift(@args);
+           $dscp = shift(@args) || '';
        }
        my @val;
        foreach my $layer (split(/\s+/,$dscp)) {
@@ -122,7 +123,7 @@ open - perl pragma to set default disciplines for input and output
     use open IO  => ":encoding(iso-8859-7)";
 
     use open IO  => ':locale';
-  
+
     use open ':utf8';
     use open ':locale';
     use open ':encoding(iso-8859-7)';
@@ -142,7 +143,7 @@ operators found within the lexical scope of this pragma will use the
 declared defaults.
 
 With the C<IN> subpragma you can declare the default layers
-of input sterams, and with the C<OUT> subpragma you can declare
+of input streams, and with the C<OUT> subpragma you can declare
 the default layers of output streams.  With the C<IO>  subpragma
 you can control both input and output streams simultaneously.
 
@@ -156,10 +157,10 @@ For example:
     # the :locale will probe the locale environment variables like LANG
     use open OUT => ':locale';
     open(O, ">koi8");
-    print O chr(0x430); # Unicode CYRILLIC SMALL LETTER A = KOI8-R 0xC1
+    print O chr(0x430); # Unicode CYRILLIC SMALL LETTER A = KOI8-R 0xc1
     close O;
     open(I, "<koi8");
-    printf "%#X\n", ord(<I>), "\n"; # this should print 0xC1
+    printf "%#x\n", ord(<I>), "\n"; # this should print 0xc1
     close I;
 
 These are equivalent