The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Sjis - Source code filter to escape ShiftJIS script

Install and Usage

There are two steps there:

  • You'll have to download Sjis.pm and Esjis.pm and put it in your perl lib directory.

  • You'll need to write "use Sjis;" at head of the script.

SYNOPSIS

  use Sjis;
  use Sjis ver.sion;             --- require minimum version
  use Sjis ver.sion.0;           --- expects version (match or die)
#if MULTIBYTE_ENCODING
  use Sjis qw(ord reverse getc); --- demand enhanced feature of ord, reverse, and getc
  use Sjis ver.sion qw(ord reverse getc);
  use Sjis ver.sion.0 qw(ord reverse getc);
#endif

  # "no Sjis;" not supported

  or

  $ perl Sjis.pm ShiftJIS_script.pl > Escaped_script.pl.e

  then

  $ perl Escaped_script.pl.e

  ShiftJIS_script.pl  --- script written in ShiftJIS
  Escaped_script.pl.e --- escaped script

  subroutines:
#if MULTIBYTE_ENCODING
    Sjis::ord(...);
    Sjis::reverse(...);
    Sjis::getc(...);
    Sjis::length(...);
    Sjis::substr(...);
    Sjis::index(...);
    Sjis::rindex(...);
#endif
    Sjis::eval(...);
#if MULTIBYTE_ENCODING
  functions:
    <*>
    glob(...);
    CORE::chop(...);
    CORE::ord(...);
    CORE::reverse(...);
    CORE::getc(...);
    CORE::index(...);
    CORE::rindex(...);
#endif
  dummy functions:
    utf8::upgrade(...);
    utf8::downgrade(...);
    utf8::encode(...);
    utf8::decode(...);
    utf8::is_utf8(...);
    utf8::valid(...);
    bytes::chr(...);
    bytes::index(...);
    bytes::length(...);
    bytes::ord(...);
    bytes::rindex(...);
    bytes::substr(...);

ABSTRACT

Sjis software is "middleware" between perl interpreter and your Perl script written in ShiftJIS.

Perl is optimized for problems which are about 90% working with text and about 10% everything else. Even if this "text" doesn't contain ShiftJIS, Perl3 or later can treat ShiftJIS as binary data.

By "use Sjis;", it automatically interpret your script as ShiftJIS. The various functions of perl including a regular expression can treat ShiftJIS now. The function length treats length per byte. This software does not use UTF8 flag.

Yet Another Future Of

JPerl is very useful software. -- Oops, note, this "JPerl" means "Japanized Perl" or "Japanese Perl". Therefore, it is unrelated to JPerl of the following.

 JPerl is an implementation of Perl written in Java.
 http://www.javainc.com/projects/jperl/
 
 jPerl - Perl on the JVM
 http://www.dzone.com/links/175948.html
 
 Jamie's PERL scripts for bioinformatics
 http://code.google.com/p/jperl/
 
 jperl (Jonathan Perl)
 https://github.com/jperl

Now, the last version of JPerl is 5.005_04 and is not maintained now.

Japanization modifier WATANABE Hirofumi said,

  "Because WATANABE am tired I give over maintaing JPerl."

at Slide #15: "The future of JPerl" of

ftp://ftp.oreilly.co.jp/pcjp98/watanabe/jperlconf.ppt

in The Perl Confernce Japan 1998.

When I heard it, I thought that someone excluding me would maintain JPerl. And I slept every night hanging a sock. Night and day, I kept having hope. After 10 years, I noticed that white beard exists in the sock :-)

This software is a source code filter to escape Perl script encoded by ShiftJIS given from STDIN or command line parameter. The character code is never converted by escaping the script. Neither the value of the character nor the length of the character string change even if it escapes.

I learned the following things from the successful software.

  • Upper Compatibility like Perl4 to Perl5

  • Maximum Portability like jcode.pl

  • Remains One Language Handling Raw ShiftJIS, Doesn't Use UTF8 flag like JPerl

  • Remains One Interpreter like Encode module

  • Code Set Independent like Ruby

  • Monolithic Script like cpanminus

  • There's more than one way to do it like Perl itself

I am excited about this software and Perl's future --- I hope you are too.

JRE: JPerl Runtime Environment

  +---------------------------------------+
  |        JPerl Application Script       | Your Script
  +---------------------------------------+
  |  Source Code Filter, Runtime Routine  | ex. Sjis.pm, Esjis.pm
  +---------------------------------------+
  |          PVM 5.00503 or later         | ex. perl 5.00503
  +---------------------------------------+

A Perl Virtual Machine (PVM) enables a set of computer software programs and data structures to use a virtual machine model for the execution of other computer programs and scripts. The model used by a PVM accepts a form of computer intermediate language commonly referred to as Perl byteorientedcode. This language conceptually represents the instruction set of a byte-oriented, capability architecture.

Basic Idea of Source Code Filter

I discovered this mail again recently.

[Tokyo.pm] jus Benkyoukai

http://mail.pm.org/pipermail/tokyo-pm/1999-September/001854.html

save as: SJIS.pm

  package SJIS;
  use Filter::Util::Call;
  sub multibyte_filter {
      my $status;
      if (($status = filter_read()) > 0 ) {
          s/([\x81-\x9f\xe0-\xef])([\x40-\x7e\x80-\xfc])/
              sprintf("\\x%02x\\x%02x",ord($1),ord($2))
          /eg;
      }
      $status;
  }
  sub import {
      filter_add(\&multibyte_filter);
  }
  1;

I am glad that I could confirm my idea is not so wrong.

Command-line Wildcard Expansion on DOS-like Systems

The default command shells on DOS-like systems (COMMAND.COM or cmd.exe or Win95Cmd.exe) do not expand wildcard arguments supplied to programs. Instead, import of Esjis.pm works well.

   in Esjis.pm
   #
   # @ARGV wildcard globbing
   #
   sub import {

       if ($^O =~ /\A (?: MSWin32 | NetWare | symbian | dos ) \z/oxms) {
           my @argv = ();
           for (@ARGV) {

               # has space
               if (/\A (?:$q_char)*? [ ] /oxms) {
                   if (my @glob = Esjis::glob(qq{"$_"})) {
                       push @argv, @glob;
                   }
                   else {
                       push @argv, $_;
                   }
               }

               # has wildcard metachar
               elsif (/\A (?:$q_char)*? [*?] /oxms) {
                   if (my @glob = Esjis::glob($_)) {
                       push @argv, @glob;
                   }
                   else {
                       push @argv, $_;
                   }
               }

               # no wildcard globbing
               else {
                   push @argv, $_;
               }
           }
           @ARGV = @argv;
       }
   }

Software Composition

   Sjis.pm               --- source code filter to escape ShiftJIS
   Esjis.pm              --- run-time routines for Sjis.pm

Upper Compatibility by Escaping

This software adds the function by 'Escaping' it always, and nothing of the past is broken. Therefore, 'Possible job' never becomes 'Impossible job'. This approach is effective in the field where the retreat is never permitted. It means incompatible upgrade of Perl should be rewound.

Escaping Your Script (You do)

You need write 'use Sjis;' in your script.

  ---------------------
  You do
  ---------------------
  use Sjis;
  ---------------------

#if ESCAPE_SECOND_OCTET =head1 Escaping Multiple-Octet Code (Sjis software provides)

Insert chr(0x5c) before @ [ \ ] ^ ` { | and } in multiple-octet of

  • string in single quote ('', q{}, <<'END', and qw{})

  • string in double quote ("", qq{}, <<END, <<"END", ``, qx{}, and <<`END`)

  • regexp in single quote (m'', s''', split(''), split(m''), and qr'')

  • regexp in double quote (//, m//, ??, s///, split(//), split(m//), and qr//)

  • character in tr/// (tr/// and y///)

  ex. Japanese Katakana "SO" like [ `/ ] code is "\x83\x5C" in SJIS
 
                  see     hex dump
  -----------------------------------------
  source script   "`/"    [83 5c]
  -----------------------------------------
 
  Here, use SJIS;
                          hex dump
  -----------------------------------------
  escaped script  "`\/"   [83 [5c] 5c]
  -----------------------------------------
                    ^--- escape by SJIS software
 
  by the by       see     hex dump
  -----------------------------------------
  your eye's      "`/\"   [83 5c] [5c]
  -----------------------------------------
  perl eye's      "`\/"   [83] \[5c]
  -----------------------------------------
 
                          hex dump
  -----------------------------------------
  in the perl     "`/"    [83] [5c]
  -----------------------------------------

#endif #if MULTIBYTE_ANCHORING =head1 Multiple-Octet Anchoring of Regular Expression (Sjis software provides)

Sjis software applies multiple-octet anchoring at beginning of regular expression.

  --------------------------------------------------------------------------------
  Before                  After
  --------------------------------------------------------------------------------
  m/regexp/               m/${Esjis::anchor}(?:regexp).../
  --------------------------------------------------------------------------------

#endif #if DIST_UTF2 =head1 Multiple-Octet Anchoring of Regular Expression

This software requires valid UTF8-encoded Unicode instead of using a multi-octet anchoring.

#endif #if DIST_OLDUTF8 =head1 Multiple-Octet Anchoring of Regular Expression

This software requires valid Modified UTF8-encoded Unicode instead of using a multi-octet anchoring.

#endif #if ESCAPE_SECOND_OCTET =head1 Escaping Second Octet (Sjis software provides)

Sjis software escapes second octet of multiple-octet character in regular expression.

  --------------------------------------------------------------------------------
  Before                  After
  --------------------------------------------------------------------------------
  m<...`/...>             m<...`/\...>
  --------------------------------------------------------------------------------

#endif #if MULTIBYTE_ENCODING =head1 Multiple-Octet Character Regular Expression (Sjis software provides)

Sjis software clusters multiple-octet character with quantifier, makes cluster from multiple-octet custom character classes. And makes multiple-octet version metasymbol from classic Perl character class shortcuts and POSIX-style character classes.

  --------------------------------------------------------------------------------
  Before                  After
  --------------------------------------------------------------------------------
  m/...MULTIOCT+.../      m/...(?:MULTIOCT)+.../
  m/...[AN-EM].../        m/...(?:A[N-Z]|[B-D][A-Z]|E[A-M]).../
  m/...\D.../             m/...(?:${Esjis::eD}).../
  m/...[[:^digit:]].../   m/...(?:${Esjis::not_digit}).../
  --------------------------------------------------------------------------------

#endif =head1 Calling 'Esjis::ignorecase()' (Sjis software provides)

Sjis software applies calling 'Esjis::ignorecase()' instead of /i modifier.

  --------------------------------------------------------------------------------
  Before                  After
  --------------------------------------------------------------------------------
  m/...$var.../i          m/...@{[Esjis::ignorecase($var)]}.../
  --------------------------------------------------------------------------------

#if MULTIBYTE_ENCODING =head1 Character-Oriented Regular Expression

Regular expression works as character-oriented that has no /b modifier.

  --------------------------------------------------------------------------------
  Before                  After
  --------------------------------------------------------------------------------
  /regexp/                /ditto$Esjis::matched/
  m/regexp/               m/ditto$Esjis::matched/
  ?regexp?                m?ditto$Esjis::matched?
  m?regexp?               m?ditto$Esjis::matched?
 
  $_ =~                   ($_ =~ m/ditto$Esjis::matched/) ?
  s/regexp/replacement/   CORE::eval{ Esjis::s_matched(); local $^W=0; my $__r=qq/replacement/; $_="${1}$__r$'"; 1 } :
                          undef
 
  $_ !~                   ($_ !~ m/ditto$Esjis::matched/) ?
  s/regexp/replacement/   1 :
                          CORE::eval{ Esjis::s_matched(); local $^W=0; my $__r=qq/replacement/; $_="${1}$__r$'"; undef }
 
  split(/regexp/)         Esjis::split(qr/regexp/)
  split(m/regexp/)        Esjis::split(qr/regexp/)
  split(qr/regexp/)       Esjis::split(qr/regexp/)
  qr/regexp/              qr/ditto$Esjis::matched/
  --------------------------------------------------------------------------------

Byte-Oriented Regular Expression

Regular expression works as byte-oriented that has /b modifier.

  --------------------------------------------------------------------------------
  Before                  After
  --------------------------------------------------------------------------------
  /regexp/b               /(?:regexp)$Esjis::matched/
  m/regexp/b              m/(?:regexp)$Esjis::matched/
  ?regexp?b               m?regexp$Esjis::matched?
  m?regexp?b              m?regexp$Esjis::matched?
 
  $_ =~                   ($_ =~ m/(\G[\x00-\xFF]*?)(?:regexp)$Esjis::matched/) ?
  s/regexp/replacement/b  CORE::eval{ Esjis::s_matched(); local $^W=0; my $__r=qq/replacement/; $_="${1}$__r$'"; 1 } :
                          undef
 
  $_ !~                   ($_ !~ m/(\G[\x00-\xFF]*?)(?:regexp)$Esjis::matched/) ?
  s/regexp/replacement/b  1 :
                          CORE::eval{ Esjis::s_matched(); local $^W=0; my $__r=qq/replacement/; $_="${1}$__r$'"; undef }
 
  split(/regexp/b)        split(qr/regexp/)
  split(m/regexp/b)       split(qr/regexp/)
  split(qr/regexp/b)      split(qr/regexp/)
  qr/regexp/b             qr/(?:regexp)$Esjis::matched/
  --------------------------------------------------------------------------------

#endif =head1 Escaping Character Classes (Esjis.pm provides)

The character classes are redefined as follows to backward compatibility.

  ---------------------------------------------------------------
  Before        After
  ---------------------------------------------------------------
   .            ${Esjis::dot}
                ${Esjis::dot_s}    (/s modifier)
  \d            [0-9]              (universally)
  \s            \s
  \w            [0-9A-Z_a-z]       (universally)
  \D            ${Esjis::eD}
  \S            ${Esjis::eS}
  \W            ${Esjis::eW}
  \h            [\x09\x20]
  \v            [\x0A\x0B\x0C\x0D]
  \H            ${Esjis::eH}
  \V            ${Esjis::eV}
  \C            [\x00-\xFF]
  \X            X                  (so, just 'X')
  \R            ${Esjis::eR}
  \N            ${Esjis::eN}
  ---------------------------------------------------------------

Also POSIX-style character classes.

  ---------------------------------------------------------------
  Before        After
  ---------------------------------------------------------------
  [:alnum:]     [\x30-\x39\x41-\x5A\x61-\x7A]
  [:alpha:]     [\x41-\x5A\x61-\x7A]
  [:ascii:]     [\x00-\x7F]
  [:blank:]     [\x09\x20]
  [:cntrl:]     [\x00-\x1F\x7F]
  [:digit:]     [\x30-\x39]
  [:graph:]     [\x21-\x7F]
  [:lower:]     [\x61-\x7A]
                [\x41-\x5A\x61-\x7A]     (/i modifier)
  [:print:]     [\x20-\x7F]
  [:punct:]     [\x21-\x2F\x3A-\x3F\x40\x5B-\x5F\x60\x7B-\x7E]
  [:space:]     [\s\x0B]
  [:upper:]     [\x41-\x5A]
                [\x41-\x5A\x61-\x7A]     (/i modifier)
  [:word:]      [\x30-\x39\x41-\x5A\x5F\x61-\x7A]
  [:xdigit:]    [\x30-\x39\x41-\x46\x61-\x66]
  [:^alnum:]    ${Esjis::not_alnum}
  [:^alpha:]    ${Esjis::not_alpha}
  [:^ascii:]    ${Esjis::not_ascii}
  [:^blank:]    ${Esjis::not_blank}
  [:^cntrl:]    ${Esjis::not_cntrl}
  [:^digit:]    ${Esjis::not_digit}
  [:^graph:]    ${Esjis::not_graph}
  [:^lower:]    ${Esjis::not_lower}
                ${Esjis::not_lower_i}    (/i modifier)
  [:^print:]    ${Esjis::not_print}
  [:^punct:]    ${Esjis::not_punct}
  [:^space:]    ${Esjis::not_space}
  [:^upper:]    ${Esjis::not_upper}
                ${Esjis::not_upper_i}    (/i modifier)
  [:^word:]     ${Esjis::not_word}
  [:^xdigit:]   ${Esjis::not_xdigit}
  ---------------------------------------------------------------

\b and \B are redefined as follows to backward compatibility.

  ---------------------------------------------------------------
  Before      After
  ---------------------------------------------------------------
  \b          ${Esjis::eb}
  \B          ${Esjis::eB}
  ---------------------------------------------------------------

Definitions in Esjis.pm.

  ---------------------------------------------------------------------------------------------------------------------------------------------------------
  After                    Definition
  ---------------------------------------------------------------------------------------------------------------------------------------------------------
#if MULTIBYTE_ANCHORING
  ${Esjis::anchor}         qr{\G(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])*?}
#endif
#if DIST_GB18030
                           for over 32766 octets string on ActivePerl5.6 and Perl5.10 or later
                           qr{\G(?(?=.{0,32766}\z)\G(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])*?|(?(?=[\x00-\x80\xFF]+\z).*?|(?:.*?[^\x30-\x39\x81-\xFE](?>[\x30-\x39]|[\x81-\xFE][\x81-\xFE]|[\x81-\xFE][\x30-\x39][\x81-\xFE][\x30-\x39])*?)))}oxms
#endif
#if DIST_EUCTW
                           for over 32766 octets string on ActivePerl5.6 and Perl5.10 or later
                           qr{\G(?(?=.{0,32766}\z)\G(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])*?|(?(?=[\x00-\x8D\x8F-\xA0\xFF]+\z).*?|(?:.*?[^\x8E\xA1-\xFE](?>[\xA1-\xFE][\xA1-\xFE]|\x8E[\xA1-\xB0][\xA1-\xFE][\xA1-\xFE])*?)))}oxms
#endif
#if DIST_EUCJP
                           for over 32766 octets string on ActivePerl5.6 and Perl5.10 or later
                           qr{\G(?(?=.{0,32766}\z)\G(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])*?|(?(?=[\x00-\x8D\x90-\xA0\xFF]+\z).*?|(?:.*?[^\x8E\x8F\xA1-\xFE](?>[\x8E\xA1-\xFE][\xA1-\xFE]|\x8F[\xA1-\xFE][\xA1-\xFE])*?)))}oxms
#endif
#if DIST_INFORMIXV6ALS
                           for over 32766 octets string on ActivePerl5.6 and Perl5.10 or later
                           qr{\G(?(?=.{0,32766}\z)\G(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])*?|(?(?=[\x00-\x80\xA0-\xDF\xFE]+\z).*?|(?:.*?[\x00-\x80\xA0-\xDF\xFF](?>[\x81-\x9F\xE0-\xFC][\x40-\x7E\x80-\xFC]|\xFD[\xA1-\xFE][\xA1-\xFE]|\xFE)*?)))}oxms
#endif
#if LONG_STRING_FOR_RE
                           for over 32766 octets string on ActivePerl5.6 and Perl5.10 or later
                           qr{\G(?(?=.{0,32766}\z)\G(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])*?|(?(?=[$sbcs]+\z).*?|(?:.*?[$sbcs](?:[^$sbcs][^$sbcs])*?)))}oxms
#endif
  ${Esjis::dot}            qr{(?>[^\x81-\x9F\xE0-\xFC\x0A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::dot_s}          qr{(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::eD}             qr{(?>[^\x81-\x9F\xE0-\xFC0-9]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::eS}             qr{(?>[^\x81-\x9F\xE0-\xFC\s]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::eW}             qr{(?>[^\x81-\x9F\xE0-\xFC0-9A-Z_a-z]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::eH}             qr{(?>[^\x81-\x9F\xE0-\xFC\x09\x20]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::eV}             qr{(?>[^\x81-\x9F\xE0-\xFC\x0A\x0B\x0C\x0D]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::eR}             qr{(?>\x0D\x0A|[\x0A\x0D])};
  ${Esjis::eN}             qr{(?>[^\x81-\x9F\xE0-\xFC\x0A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_alnum}      qr{(?>[^\x81-\x9F\xE0-\xFC\x30-\x39\x41-\x5A\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_alpha}      qr{(?>[^\x81-\x9F\xE0-\xFC\x41-\x5A\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_ascii}      qr{(?>[^\x81-\x9F\xE0-\xFC\x00-\x7F]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_blank}      qr{(?>[^\x81-\x9F\xE0-\xFC\x09\x20]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_cntrl}      qr{(?>[^\x81-\x9F\xE0-\xFC\x00-\x1F\x7F]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_digit}      qr{(?>[^\x81-\x9F\xE0-\xFC\x30-\x39]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_graph}      qr{(?>[^\x81-\x9F\xE0-\xFC\x21-\x7F]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_lower}      qr{(?>[^\x81-\x9F\xE0-\xFC\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_lower_i}    qr{(?>[^\x81-\x9F\xE0-\xFC\x41-\x5A\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])}; # Perl 5.16 compatible
# ${Esjis::not_lower_i}    qr{(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};                   # older Perl compatible
  ${Esjis::not_print}      qr{(?>[^\x81-\x9F\xE0-\xFC\x20-\x7F]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_punct}      qr{(?>[^\x81-\x9F\xE0-\xFC\x21-\x2F\x3A-\x3F\x40\x5B-\x5F\x60\x7B-\x7E]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_space}      qr{(?>[^\x81-\x9F\xE0-\xFC\s\x0B]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_upper}      qr{(?>[^\x81-\x9F\xE0-\xFC\x41-\x5A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_upper_i}    qr{(?>[^\x81-\x9F\xE0-\xFC\x41-\x5A\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])}; # Perl 5.16 compatible
# ${Esjis::not_upper_i}    qr{(?>[^\x81-\x9F\xE0-\xFC]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};                   # older Perl compatible
  ${Esjis::not_word}       qr{(?>[^\x81-\x9F\xE0-\xFC\x30-\x39\x41-\x5A\x5F\x61-\x7A]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  ${Esjis::not_xdigit}     qr{(?>[^\x81-\x9F\xE0-\xFC\x30-\x39\x41-\x46\x61-\x66]|[\x81-\x9F\xE0-\xFC][\x00-\xFF])};
  
  # This solution is not perfect. I beg better solution from you who are reading this.
  ${Esjis::eb}             qr{(?:\A(?=[0-9A-Z_a-z])|(?<=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF])(?=[0-9A-Z_a-z])|(?<=[0-9A-Z_a-z])(?=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF]|\z))};
  ${Esjis::eB}             qr{(?:(?<=[0-9A-Z_a-z])(?=[0-9A-Z_a-z])|(?<=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF])(?=[\x00-\x2F\x40\x5B-\x5E\x60\x7B-\xFF]))};
  ---------------------------------------------------------------------------------------------------------------------------------------------------------

Un-Escaping \ of \b{}, \B{}, \N{}, \p{}, \P{}, and \X (Sjis software provides)

Sjis software removes '\' at head of alphanumeric regexp metasymbols \b{}, \B{}, \N{}, \p{}, \P{} and \X. By this method, you can avoid the trap of the abstraction.

See also, Deprecate literal unescaped "{" in regexes. http://perl5.git.perl.org/perl.git/commit/2a53d3314d380af5ab5283758219417c6dfa36e9

  ------------------------------------
  Before           After
  ------------------------------------
  \b{...}          b\{...}
  \B{...}          B\{...}
  \N{CHARNAME}     N\{CHARNAME}
  \p{L}            p\{L}
  \p{^L}           p\{^L}
  \p{\^L}          p\{\^L}
  \pL              pL
  \P{L}            P\{L}
  \P{^L}           P\{^L}
  \P{\^L}          P\{\^L}
  \PL              PL
  \X               X
  ------------------------------------

Escaping Built-in Functions (Sjis software provides)

Insert 'Esjis::' at head of function name. Esjis.pm provides your script Esjis::* subroutines.

  -------------------------------------------
  Before      After            Works as
  -------------------------------------------
#if MULTIBYTE_ENCODING
  length      length           Byte
  substr      substr           Byte
  pos         pos              Byte
  split       Esjis::split     Character
  tr///       Esjis::tr        Character
  tr///b      tr///            Byte
  tr///B      tr///            Byte
  y///        Esjis::tr        Character
  y///b       tr///            Byte
  y///B       tr///            Byte
  chop        Esjis::chop      Character
#endif
#if MULTIBYTE_ANCHORING
  index       Esjis::index     Character
  rindex      Esjis::rindex    Character
#endif
  lc          Esjis::lc        Character
  lcfirst     Esjis::lcfirst   Character
  uc          Esjis::uc        Character
  ucfirst     Esjis::ucfirst   Character
  fc          Esjis::fc        Character
  chr         Esjis::chr       Character
  glob        Esjis::glob      Character
#if ESCAPE_SECOND_OCTET
  lstat       Esjis::lstat     Character
  opendir     Esjis::opendir   Character
  stat        Esjis::stat      Character
  unlink      Esjis::unlink    Character
  chdir       Esjis::chdir     Character
  do          Esjis::do        Character
  require     Esjis::require   Character
#endif
  -------------------------------------------

  ------------------------------------------------------------------------------------------------------------------------
  Before                   After
  ------------------------------------------------------------------------------------------------------------------------
  use Perl::Module;        BEGIN { Esjis::require 'Perl/Module.pm'; Perl::Module->import() if Perl::Module->can('import'); }
  use Perl::Module @list;  BEGIN { Esjis::require 'Perl/Module.pm'; Perl::Module->import(@list) if Perl::Module->can('import'); }
  use Perl::Module ();     BEGIN { Esjis::require 'Perl/Module.pm'; }
  no Perl::Module;         BEGIN { Esjis::require 'Perl/Module.pm'; Perl::Module->unimport() if Perl::Module->can('unimport'); }
  no Perl::Module @list;   BEGIN { Esjis::require 'Perl/Module.pm'; Perl::Module->unimport(@list) if Perl::Module->can('unimport'); }
  no Perl::Module ();      BEGIN { Esjis::require 'Perl/Module.pm'; }
  ------------------------------------------------------------------------------------------------------------------------

#if ESCAPE_SECOND_OCTET =head1 Escaping File Test Operators (Sjis software provides)

Insert 'Esjis::' instead of '-' of operator.

  Available in MSWin32, MacOS, and UNIX-like systems
  --------------------------------------------------------------------------
  Before   After      Meaning
  --------------------------------------------------------------------------
  -r       Esjis::r   File or directory is readable by this (effective) user or group
  -w       Esjis::w   File or directory is writable by this (effective) user or group
  -e       Esjis::e   File or directory name exists
  -x       Esjis::x   File or directory is executable by this (effective) user or group
  -z       Esjis::z   File exists and has zero size (always false for directories)
  -f       Esjis::f   Entry is a plain file
  -d       Esjis::d   Entry is a directory
  -t       -t         The filehandle is a TTY (as reported by the isatty() system function;
                      filenames can't be tested by this test)
  -T       Esjis::T   File looks like a "text" file
  -B       Esjis::B   File looks like a "binary" file
  -M       Esjis::M   Modification age (measured in days)
  -A       Esjis::A   Access age (measured in days)
  -C       Esjis::C   Inode-modification age (measured in days)
  -s       Esjis::s   File or directory exists and has nonzero size
                      (the value is the size in bytes)
  --------------------------------------------------------------------------
  
  Available in MacOS and UNIX-like systems
  --------------------------------------------------------------------------
  Before   After      Meaning
  --------------------------------------------------------------------------
  -R       Esjis::R   File or directory is readable by this real user or group
  -W       Esjis::W   File or directory is writable by this real user or group
  -X       Esjis::X   File or directory is executable by this real user or group
  -l       Esjis::l   Entry is a symbolic link
  -S       Esjis::S   Entry is a socket
  --------------------------------------------------------------------------
  
  Not available in MSWin32 and MacOS
  --------------------------------------------------------------------------
  Before   After      Meaning
  --------------------------------------------------------------------------
  -o       Esjis::o   File or directory is owned by this (effective) user
  -O       Esjis::O   File or directory is owned by this real user
  -p       Esjis::p   Entry is a named pipe (a "fifo")
  -b       Esjis::b   Entry is a block-special file (like a mountable disk)
  -c       Esjis::c   Entry is a character-special file (like an I/O device)
  -u       Esjis::u   File or directory is setuid
  -g       Esjis::g   File or directory is setgid
  -k       Esjis::k   File or directory has the sticky bit set
  --------------------------------------------------------------------------

-w only inspects the read-only file attribute (FILE_ATTRIBUTE_READONLY), which determines whether the directory can be deleted, not whether it can be written to. Directories always have read and write access unless denied by discretionary access control lists (DACLs). (MSWin32) -R, -W, -X, -O are indistinguishable from -r, -w, -x, -o. (MSWin32) -g, -k, -l, -u, -A are not particularly meaningful. (MSWin32) -x (or -X) determine if a file ends in one of the executable suffixes. -S is meaningless. (MSWin32)

As of Perl 5.00503, as a form of purely syntactic sugar, you can stack file test operators, in a way that -w -x $file is equivalent to -x $file && -w _ .

  if ( -w -r $file ) {
      print "The file is both readable and writable!\n";
  }

#endif #if MULTIBYTE_ENCODING =head1 Escaping Function Name (You do)

You need write 'Sjis::' at head of function name when you want character- oriented subroutine. See 'Character-Oriented Subroutines'.

  --------------------------------------------------------
  Function   Character-Oriented   Description
  --------------------------------------------------------
  ord        Sjis::ord
  reverse    Sjis::reverse
  getc       Sjis::getc
  length     Sjis::length
  substr     Sjis::substr
  index      Sjis::index          See 'About Indexes'
  rindex     Sjis::rindex         See 'About Rindexes'
  eval       Sjis::eval
  --------------------------------------------------------

  About Indexes
  -------------------------------------------------------------------------
  Function       Works as    Returns as   Description
  -------------------------------------------------------------------------
  index          Character   Byte         JPerl semantics (most useful)
  (same as Esjis::index)
  Sjis::index    Character   Character    Character-oriented semantics
  CORE::index    Byte        Byte         Byte-oriented semantics
  (nothing)      Byte        Character    (most useless)
  -------------------------------------------------------------------------

  About Rindexes
  -------------------------------------------------------------------------
  Function       Works as    Returns as   Description
  -------------------------------------------------------------------------
  rindex         Character   Byte         JPerl semantics (most useful)
  (same as Esjis::rindex)
  Sjis::rindex   Character   Character    Character-oriented semantics
  CORE::rindex   Byte        Byte         Byte-oriented semantics
  (nothing)      Byte        Character    (most useless)
  -------------------------------------------------------------------------

Character-Oriented Subsroutines

  • Ordinal Value of Character

      $ord = Sjis::ord($string);
    
      This subroutine returns the numeric value (ASCII or ShiftJIS character) of the
      first character of $string, not Unicode. If $string is omitted, it uses $_.
      The return value is always unsigned.
    
      If you import ord "use Sjis qw(ord);", ord of your script will be rewritten in
      Sjis::ord. Sjis::ord is not compatible with ord of JPerl.
  • Reverse List or String

      @reverse = Sjis::reverse(@list);
      $reverse = Sjis::reverse(@list);
    
      In list context, this subroutine returns a list value consisting of the elements
      of @list in the opposite order.
    
      In scalar context, the subroutine concatenates all the elements of @list and
      then returns the reverse of that resulting string, character by character.
    
      If you import reverse "use Sjis qw(reverse);", reverse of your script will be
      rewritten in Sjis::reverse. Sjis::reverse is not compatible with reverse of
      JPerl.
    
      Even if you do not know this subroutine, there is no problem. This subroutine
      can be created with
    
      $rev = join('', reverse(split(//, $jstring)));
    
      as before.
    
      See:
      P.558 JPerl (Japanese Perl)
      Appendix C Supplement the Japanese version
      ISBN 4-89052-384-7 PERL PUROGURAMINGU
  • Returns Next Character

      $getc = Sjis::getc(FILEHANDLE);
      $getc = Sjis::getc($filehandle);
      $getc = Sjis::getc;
    
      This subroutine returns the next character from the input file attached to
      FILEHANDLE. It returns undef at end-of-file, or if an I/O error was encountered.
      If FILEHANDLE is omitted, the subroutine reads from STDIN.
    
      This subroutine is somewhat slow, but it's occasionally useful for
      single-character input from the keyboard -- provided you manage to get your
      keyboard input unbuffered. This subroutine requests unbuffered input from the
      standard I/O library. Unfortunately, the standard I/O library is not so standard
      as to provide a portable way to tell the underlying operating system to supply
      unbuffered keyboard input to the standard I/O system. To do that, you have to
      be slightly more clever, and in an operating-system-dependent fashion. Under
      Unix you might say this:
    
      if ($BSD_STYLE) {
          system "stty cbreak </dev/tty >/dev/tty 2>&1";
      }
      else {
          system "stty", "-icanon", "eol", "\001";
      }
    
      $key = Sjis::getc;
    
      if ($BSD_STYLE) {
          system "stty -cbreak </dev/tty >/dev/tty 2>&1";
      }
      else {
          system "stty", "icanon", "eol", "^@"; # ASCII NUL
      }
      print "\n";
    
      This code puts the next character typed on the terminal in the string $key. If
      your stty program has options like cbreak, you'll need to use the code where
      $BSD_STYLE is true. Otherwise, you'll need to use the code where it is false.
    
      If you import getc "use Sjis qw(getc);", getc of your script will be rewritten
      in Sjis::getc. Sjis::getc is not compatible with getc of JPerl.
  • Length by ShiftJIS Character

      $length = Sjis::length($string);
      $length = Sjis::length();
    
      This subroutine returns the length in characters (programmer-visible characters)
      of the scalar value $string. If $string is omitted, it returns the Sjis::length
      of $_.
    
      Do not try to use Sjis::length to find the size of an array or hash. Use scalar
      @array for the size of an array, and scalar keys %hash for the number of key/value
      pairs in a hash. (The scalar is typically omitted when redundant.)
    
      To find the length of a string in bytes rather than characters, say simply:
    
      $bytes = length($string);
    
      Even if you do not know this subroutine, there is no problem. This subroutine
      can be created with
    
      $len = split(//, $jstring);
    
      as before.
    
      See:
      P.558 JPerl (Japanese Perl)
      Appendix C Supplement the Japanese version
      ISBN 4-89052-384-7 PERL PUROGURAMINGU
  • Substr by ShiftJIS Character

      $substr = Sjis::substr($string,$offset,$length,$replacement);
      $substr = Sjis::substr($string,$offset,$length);
      $substr = Sjis::substr($string,$offset);
    
      This subroutine extracts a substring out of the string given by $string and returns
      it. The substring is extracted starting at $offset characters from the front of
      the string. First character is at offset zero. If $offset is negative, starts that
      far back from the end of the string.
      If $length is omitted, returns everything through the end of the string. If $length
      is negative, leaves that many characters off the end of the string. Otherwise,
      $length indicates the length of the substring to extract, which is sort of what
      you'd expect.
    
      my $s = "The black cat climbed the green tree";
      my $color  = Sjis::substr $s, 4, 5;      # black
      my $middle = Sjis::substr $s, 4, -11;    # black cat climbed the
      my $end    = Sjis::substr $s, 14;        # climbed the green tree
      my $tail   = Sjis::substr $s, -4;        # tree
      my $z      = Sjis::substr $s, -4, 2;     # tr
    
      If Perl version 5.14 or later, you can use the Sjis::substr() subroutine as an
      lvalue. In its case $string must itself be an lvalue. If you assign something
      shorter than $length, the string will shrink, and if you assign something longer
      than $length, the string will grow to accommodate it. To keep the string the
      same length, you may need to pad or chop your value using sprintf.
    
      If $offset and $length specify a substring that is partly outside the string,
      only the part within the string is returned. If the substring is beyond either
      end of the string, Sjis::substr() returns the undefined value and produces a
      warning. When used as an lvalue, specifying a substring that is entirely outside
      the string raises an exception. Here's an example showing the behavior for
      boundary cases:
    
      my $name = 'fred';
      Sjis::substr($name, 4) = 'dy';         # $name is now 'freddy'
      my $null = Sjis::substr $name, 6, 2;   # returns "" (no warning)
      my $oops = Sjis::substr $name, 7;      # returns undef, with warning
      Sjis::substr($name, 7) = 'gap';        # raises an exception
    
      An alternative to using Sjis::substr() as an lvalue is to specify the replacement
      string as the 4th argument. This allows you to replace parts of the $string and
      return what was there before in one operation, just as you can with splice().
    
      my $s = "The black cat climbed the green tree";
      my $z = Sjis::substr $s, 14, 7, "jumped from";    # climbed
      # $s is now "The black cat jumped from the green tree"
    
      Note that the lvalue returned by the three-argument version of Sjis::substr() acts
      as a 'magic bullet'; each time it is assigned to, it remembers which part of the
      original string is being modified; for example:
    
      $x = '1234';
      for (Sjis::substr($x,1,2)) {
          $_ = 'a';   print $x,"\n";    # prints 1a4
          $_ = 'xyz'; print $x,"\n";    # prints 1xyz4
          $x = '56789';
          $_ = 'pq';  print $x,"\n";    # prints 5pq9
      }
    
      With negative offsets, it remembers its position from the end of the string when
      the target string is modified:
    
      $x = '1234';
      for (Sjis::substr($x, -3, 2)) {
          $_ = 'a';   print $x,"\n";    # prints 1a4, as above
          $x = 'abcdefg';
          print $_,"\n";                # prints f
      }
    
      Prior to Perl version 5.10, the result of using an lvalue multiple times was
      unspecified. Prior to 5.16, the result with negative offsets was unspecified.
  • Index by ShiftJIS Character

      $index = Sjis::index($string,$substring,$offset);
      $index = Sjis::index($string,$substring);
    
      This subroutine searches for one string within another. It returns the character
      position of the first occurrence of $substring in $string. The $offset, if
      specified, says how many characters from the start to skip before beginning to
      look. Positions are based at 0. If the substring is not found, the subroutine
      returns one less than the base, ordinarily -1. To work your way through a string,
      you might say:
    
      $pos = -1;
      while (($pos = Sjis::index($string, $lookfor, $pos)) > -1) {
          print "Found at $pos\n";
          $pos++;
      }
  • Rindex by ShiftJIS Character

      $rindex = Sjis::rindex($string,$substring,$offset);
      $rindex = Sjis::rindex($string,$substring);
    
      This subroutine works just like Sjis::index except that it returns the character
      position of the last occurrence of $substring in $string (a reverse Sjis::index).
      The subroutine returns -1 if $substring is not found. $offset, if specified, is
      the rightmost character position that may be returned. To work your way through
      a string backward, say:
    
      $pos = Sjis::length($string);
      while (($pos = Sjis::rindex($string, $lookfor, $pos)) >= 0) {
          print "Found at $pos\n";
          $pos--;
      }
  • Eval ShiftJIS Script

      $eval = Sjis::eval { block };
      $eval = Sjis::eval $expr;
      $eval = Sjis::eval;
    
      The Sjis::eval keyword serves two distinct but related purposes in JPerl.
      These purposes are represented by two forms of syntax, Sjis::eval { block }
      and Sjis::eval $expr. The first form traps runtime exceptions (errors)
      that would otherwise prove fatal, similar to the "try block" construct in
      C++ or Java. The second form compiles and executes little bits of code on
      the fly at runtime, and also (conveniently) traps any exceptions just like
      the first form. But the second form runs much slower than the first form,
      since it must parse the string every time. On the other hand, it is also
      more general. Whichever form you use, Sjis::eval is the preferred way to do
      all exception handling in JPerl.
    
      For either form of Sjis::eval, the value returned from an Sjis::eval is
      the value of the last expression evaluated, just as with subroutines.
      Similarly, you may use the return operator to return a value from the
      middle of the eval. The expression providing the return value is evaluated
      in void, scalar, or list context, depending on the context of the
      Sjis::eval itself. See wantarray for more on how the evaluation context
      can be determined.
    
      If there is a trappable error (including any produced by the die operator),
      Sjis::eval returns undef and puts the error message (or object) in $@. If
      there is no error, $@ is guaranteed to be set to the null string, so you
      can test it reliably afterward for errors. A simple Boolean test suffices:
    
          Sjis::eval { ... }; # trap runtime errors
          if ($@) { ... }     # handle error
    
      (Prior to Perl 5.16, a bug caused undef to be returned in list context for
      syntax errors, but not for runtime errors.)
    
      The Sjis::eval { block } form is syntax checked and compiled at compile time,
      so it is just as efficient at runtime as any other block. (People familiar
      with the slow Sjis::eval $expr form are occasionally confused on this issue.)
      Because the { block } is compiled when the surrounding code is, this form of
      Sjis::eval cannot trap syntax errors.
    
      The Sjis::eval $expr form can trap syntax errors because it parses the code
      at runtime. (If the parse is unsuccessful, it places the parse error in $@,
      as usual.) If $expr is omitted, evaluates $_ .
    
      Otherwise, it executes the value of $expr as though it were a little JPerl
      script. The code is executed in the context of the current of the current
      JPerl script, which means that it can see any enclosing lexicals from a
      surrounding scope, and that any nonlocal variable settings remain in effect
      after the Sjis::eval is complete, as do any subroutine or format definitions.
      The code of the Sjis::eval is treated as a block, so any locally scoped
      variables declared within the Sjis::eval last only until the Sjis::eval is
      done. (See my and local.) As with any code in a block, a final semicolon is
      not required.
    
      Sjis::eval will be escaped as follows:
    
      -------------------------------------------------
      Before                  After
      -------------------------------------------------
      Sjis::eval { block }    eval { block }
      Sjis::eval $expr        eval Sjis::escape $expr
      Sjis::eval              eval Sjis::escape
      -------------------------------------------------
    
      To tell the truth, the subroutine Sjis::eval does not exist. If it exists,
      you will troubled, when Sjis::eval has a parameter that is single quoted
      string included my variables. Sjis::escape is a subroutine that makes Perl
      script from JPerl script.
    
      Here is a simple JPerl shell. It prompts the user to enter a string of
      arbitrary JPerl code, compiles and executes that string, and prints whatever
      error occurred:
    
          #!/usr/bin/perl
          # jperlshell.pl - simple JPerl shell
          use Sjis;
          print "\nEnter some JPerl code: ";
          while (<STDIN>) {
              Sjis::eval;
              print $@;
              print "\nEnter some more JPerl code: ";
          }
    
      Here is a rename.pl script to do a mass renaming of files using a JPerl
      expression:
    
          #!/usr/bin/perl
          # rename.pl - change filenames
          use Sjis;
          $op = shift;
          for (@ARGV) {
              $was = $_;
              Sjis::eval $op;
              die if $@;
              # next line calls the built-in function, not
              # the script by the same name
              if ($was ne $_) {
                  print STDERR "rename $was --> $_\n";
                  rename($was,$_);
              }
          }
    
      You'd use that script like this:
    
          C:\WINDOWS> perl rename.pl 's/\.orig$//' *.orig
          C:\WINDOWS> perl rename.pl 'y/A-Z/a-z/ unless /^Make/' *
          C:\WINDOWS> perl rename.pl '$_ .= ".bad"' *.f
    
      Since Sjis::eval traps errors that would otherwise prove fatal, it is useful
      for determining whether particular features (such as fork or symlink) are
      implemented.
    
      Because Sjis::eval { block } is syntax checked at compile time, any syntax
      error is reported earlier. Therefore, if your code is invariant and both
      Sjis::eval $expr and Sjis::eval { block } will suit your purposes equally
      well, the { block } form is preferred. For example:
    
          # make divide-by-zero nonfatal
          Sjis::eval { $answer = $a / $b; };
          warn $@ if $@;
    
          # same thing, but less efficient if run multiple times
          Sjis::eval '$answer = $a / $b';
          warn $@ if $@;
    
          # a compile-time syntax error (not trapped)
          Sjis::eval { $answer = }; # WRONG
    
          # a runtime syntax error
          Sjis::eval '$answer =';   # sets $@
    
      Here, the code in the { block } has to be valid JPerl code to make it past
      the compile phase. The code in the $expr doesn't get examined until runtime,
      so it doesn't cause an error until runtime.
    
      Using the Sjis::eval { block } form as an exception trap in libraries does
      have some issues. Due to the current arguably broken state of __DIE__ hooks,
      you may wish not to trigger any __DIE__ hooks that user code may have
      installed. You can use the local $SIG{__DIE__} construct for this purpose,
      as this example shows:
    
          # a private exception trap for divide-by-zero
          Sjis::eval { local $SIG{'__DIE__'}; $answer = $a / $b; };
          warn $@ if $@;
    
      This is especially significant, given that __DIE__ hooks can call die again,
      which has the effect of changing their error messages:
    
          # __DIE__ hooks may modify error messages
          {
              local $SIG{'__DIE__'} =
                  sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
              Sjis::eval { die "foo lives here" };
              print $@ if $@;                # prints "bar lives here"
          }
    
      Because this promotes action at a distance, this counterintuitive behavior
      may be fixed in a future release.
    
      With an Sjis::eval, you should be especially careful to remember what's being
      looked at when:
    
          Sjis::eval $x;        # CASE 1
          Sjis::eval "$x";      # CASE 2
    
          Sjis::eval '$x';      # CASE 3
          Sjis::eval { $x };    # CASE 4
    
          Sjis::eval "\$$x++";  # CASE 5
          $$x++;                # CASE 6
    
      CASEs 1 and 2 above behave identically: they run the code contained in the
      variable $x. (Although CASE 2 has misleading double quotes making the reader
      wonder what else might be happening (nothing is).) CASEs 3 and 4 likewise
      behave in the same way: they run the code '$x' , which does nothing but return
      the value of $x. (CASE 4 is preferred for purely visual reasons, but it also
      has the advantage of compiling at compile-time instead of at run-time.) CASE 5
      is a place where normally you would like to use double quotes, except that in
      this particular situation, you can just use symbolic references instead, as
      in CASE 6.
    
      Before Perl 5.14, the assignment to $@ occurred before restoration of
      localized variables, which means that for your code to run on older versions,
      a temporary is required if you want to mask some but not all errors:
    
          # alter $@ on nefarious repugnancy only
          {
              my $e;
              {
                  local $@; # protect existing $@
                  Sjis::eval { test_repugnancy() };
                  # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only
                  $@ =~ /nefarious/ and $e = $@;
              }
              die $e if defined $e
          }
    
      The block of Sjis::eval { block } does not count as a loop, so the loop
      control statements next, last, or redo cannot be used to leave or restart the
      block.
  • Filename Globbing

      @glob = glob($expr);
      $glob = glob($expr);
      @glob = glob;
      $glob = glob;
      @glob = <*>;
      $glob = <*>;
    
      Performs filename expansion (globbing) on $expr, returning the next successive
      name on each call. If $expr is omitted, $_ is globbed instead.
    
      This operator is implemented via the Esjis::glob() subroutine. See Esjis::glob
      of Esjis.pm for details.

Byte-Oriented Functions

  • Chop Byte String

      $byte = CORE::chop($string);
      $byte = CORE::chop(@list);
      $byte = CORE::chop;
    
      This function chops off the last byte of a string variable and returns the
      byte chopped. The CORE::chop operator is used primarily to remove the newline
      from the end of an input record, and is more efficient than using a
      substitution (s/\n$//). If that's all you're doing, then it would be safer to
      use chomp, since CORE::chop always shortens the string no matter what's there,
      and chomp is more selective.
    
      You cannot CORE::chop a literal, only a variable.
    
      If you CORE::chop a @list of variables, each string in the list is chopped:
    
      @lines = `cat myfile`;
      CORE::chop @lines;
    
      You can CORE::chop anything that is an lvalue, including an assignment:
    
      CORE::chop($cwd = `pwd`);
      CORE::chop($answer = <STDIN>);
    
      This is different from:
    
      $answer = CORE::chop($temp = <STDIN>); # WRONG
    
      which puts a newline into $answer because CORE::chop returns the byte chopped,
      not the remaining string (which is in $tmp). One way to get the result
      intended here is with substr:
    
      $answer = substr <STDIN>, 0, -1;
    
      But this is more commonly written as:
    
      CORE::chop($answer = <STDIN>);
    
      In the most general case, CORE::chop can be expressed in terms of substr:
    
      $last_byte = CORE::chop($var);
      $last_byte = substr($var, -1, 1, ""); # same thing
    
      Once you understand this equivalence, you can use it to do bigger chops. To
      CORE::chop more than one byte, use substr as an lvalue, assigning a null
      string. The following removes the last five bytes of $caravan:
    
      substr($caravan, -5) = "";
    
      The negative subscript causes substr to count from the end of the string
      instead of the beginning. If you wanted to save the bytes so removed, you
      could use the four-argument form of substr, creating something of a quintuple
      CORE::chop:
    
      $tail = substr($caravan, -5, 5, "");
    
      If no argument is given, the function chops the $_ variable.
  • Ordinal Value of Byte

      $ord = CORE::ord($expr);
    
      This function returns the numeric value of the first byte of $expr, regardless
      of "use Sjis qw(ord);" exists or not. If $expr is omitted, it uses $_.
      The return value is always unsigned.
    
      If you want a signed value, use unpack('c',$expr). If you want all the bytes of
      the string converted to a list of numbers, use unpack('C*',$expr) instead.
  • Reverse List or Byte String

      @reverse = CORE::reverse(@list);
      $reverse = CORE::reverse(@list);
    
      In list context, this function returns a list value consisting of the elements
      of @list in the opposite order.
    
      In scalar context, the function concatenates all the elements of @list and then
      returns the reverse of that resulting string, byte by byte, regardless of
      "use Sjis qw(reverse);" exists or not.
  • Returns Next Byte

      $getc = CORE::getc(FILEHANDLE);
      $getc = CORE::getc($filehandle);
      $getc = CORE::getc;
    
      This function returns the next byte from the input file attached to FILEHANDLE.
      It returns undef at end-of-file, or if an I/O error was encountered. If
      FILEHANDLE is omitted, the function reads from STDIN.
    
      This function is somewhat slow, but it's occasionally useful for single-byte
      input from the keyboard -- provided you manage to get your keyboard input
      unbuffered. This function requests unbuffered input from the standard I/O library.
      Unfortunately, the standard I/O library is not so standard as to provide a portable
      way to tell the underlying operating system to supply unbuffered keyboard input to
      the standard I/O system. To do that, you have to be slightly more clever, and in
      an operating-system-dependent fashion. Under Unix you might say this:
    
      if ($BSD_STYLE) {
          system "stty cbreak </dev/tty >/dev/tty 2>&1";
      }
      else {
          system "stty", "-icanon", "eol", "\001";
      }
    
      $key = CORE::getc;
    
      if ($BSD_STYLE) {
          system "stty -cbreak </dev/tty >/dev/tty 2>&1";
      }
      else {
          system "stty", "icanon", "eol", "^@"; # ASCII NUL
      }
      print "\n";
    
      This code puts the next single-byte typed on the terminal in the string $key.
      If your stty program has options like cbreak, you'll need to use the code where
      $BSD_STYLE is true. Otherwise, you'll need to use the code where it is false.
  • Index by Byte String

      $index = CORE::index($string,$substring,$offset);
      $index = CORE::index($string,$substring);
    
      This function searches for one byte string within another. It returns the position
      of the first occurrence of $substring in $string. The $offset, if specified, says
      how many bytes from the start to skip before beginning to look. Positions are based
      at 0. If the substring is not found, the function returns one less than the base,
      ordinarily -1. To work your way through a string, you might say:
    
      $pos = -1;
      while (($pos = CORE::index($string, $lookfor, $pos)) > -1) {
          print "Found at $pos\n";
          $pos++;
      }
  • Rindex by Byte String

      $rindex = CORE::rindex($string,$substring,$offset);
      $rindex = CORE::rindex($string,$substring);
    
      This function works just like CORE::index except that it returns the position of
      the last occurrence of $substring in $string (a reverse CORE::index). The function
      returns -1 if not $substring is found. $offset, if specified, is the rightmost
      position that may be returned. To work your way through a string backward, say:
    
      $pos = CORE::length($string);
      while (($pos = CORE::rindex($string, $lookfor, $pos)) >= 0) {
          print "Found at $pos\n";
          $pos--;
      }

#endif =head1 Yada Yada Operator (Sjis software provides)

  The yada yada operator (noted ...) is a placeholder for code. Perl parses it
  without error, but when you try to execute a yada yada, it throws an exception
  with the text Unimplemented:

  sub unimplemented { ... }
  eval { unimplemented() };
  if ( $@ eq 'Unimplemented' ) {
      print "I found the yada yada!\n";
  }

  You can only use the yada yada to stand in for a complete statement. These
  examples of the yada yada work:

  { ... }
  sub foo { ... }
  ...;
  eval { ... };
  sub foo {
      my( $self ) = shift;
      ...;
  }
  do { my $n; ...; print 'Hurrah!' };

  The yada yada cannot stand in for an expression that is part of a larger statement
  since the ... is also the three-dot version of the range operator
  (see "Range Operators"). These examples of the yada yada are still syntax errors:

  print ...;
  open my($fh), '>', '/dev/passwd' or ...;
  if ( $condition && ... ) { print "Hello\n" };

  There are some cases where Perl can't immediately tell the difference between an
  expression and a statement. For instance, the syntax for a block and an anonymous
  hash reference constructor look the same unless there's something in the braces that
  give Perl a hint. The yada yada is a syntax error if Perl doesn't guess that the
  { ... } is a block. In that case, it doesn't think the ... is the yada yada because
  it's expecting an expression instead of a statement:

  my @transformed = map { ... } @input;  # syntax error

  You can use a ; inside your block to denote that the { ... } is a block and not a
  hash reference constructor. Now the yada yada works:

  my @transformed = map {; ... } @input; # ; disambiguates
  my @transformed = map { ...; } @input; # ; disambiguates

Un-Escaping bytes::* Subroutines (Sjis software provides)

Sjis software removes 'bytes::' at head of subroutine name.

  ---------------------------------------
  Before           After     Works as
  ---------------------------------------
  bytes::chr       chr       Byte
  bytes::index     index     Byte
  bytes::length    length    Byte
  bytes::ord       ord       Byte
  bytes::rindex    rindex    Byte
  bytes::substr    substr    Byte
  ---------------------------------------

Ignore Pragmas and Modules

  -----------------------------------------------------------
  Before                    After
  -----------------------------------------------------------
  use strict;               use strict; no strict qw(refs);
  use 5.12.0;               use 5.12.0; no strict qw(refs);
  require utf8;             # require utf8;
  require bytes;            # require bytes;
  require charnames;        # require charnames;
  require I18N::Japanese;   # require I18N::Japanese;
  require I18N::Collate;    # require I18N::Collate;
  require I18N::JExt;       # require I18N::JExt;
  require File::DosGlob;    # require File::DosGlob;
  require Wild;             # require Wild;
  require Wildcard;         # require Wildcard;
  require Japanese;         # require Japanese;
  use utf8;                 # use utf8;
  use bytes;                # use bytes;
  use charnames;            # use charnames;
  use I18N::Japanese;       # use I18N::Japanese;
  use I18N::Collate;        # use I18N::Collate;
  use I18N::JExt;           # use I18N::JExt;
  use File::DosGlob;        # use File::DosGlob;
  use Wild;                 # use Wild;
  use Wildcard;             # use Wildcard;
  use Japanese;             # use Japanese;
  no utf8;                  # no utf8;
  no bytes;                 # no bytes;
  no charnames;             # no charnames;
  no I18N::Japanese;        # no I18N::Japanese;
  no I18N::Collate;         # no I18N::Collate;
  no I18N::JExt;            # no I18N::JExt;
  no File::DosGlob;         # no File::DosGlob;
  no Wild;                  # no Wild;
  no Wildcard;              # no Wildcard;
  no Japanese;              # no Japanese;
  -----------------------------------------------------------

  Comment out pragma to ignore utf8 environment, and Esjis.pm provides these
  functions.
  • Dummy utf8::upgrade

      $num_octets = utf8::upgrade($string);
    
      Returns the number of octets necessary to represent the string.
  • Dummy utf8::downgrade

      $success = utf8::downgrade($string[, FAIL_OK]);
    
      Returns true always.
  • Dummy utf8::encode

      utf8::encode($string);
    
      Returns nothing.
  • Dummy utf8::decode

      $success = utf8::decode($string);
    
      Returns true always.
  • Dummy utf8::is_utf8

      $flag = utf8::is_utf8(STRING);
    
      Returns false always.
  • Dummy utf8::valid

      $flag = utf8::valid(STRING);
    
      Returns true always.
  • Dummy bytes::chr

      This subroutine is same as chr.
  • Dummy bytes::index

      This subroutine is same as index.
  • Dummy bytes::length

      This subroutine is same as length.
  • Dummy bytes::ord

      This subroutine is same as ord.
  • Dummy bytes::rindex

      This subroutine is same as rindex.
  • Dummy bytes::substr

      This subroutine is same as substr.

Environment Variable

 This software uses the flock function for exclusive control. The execution of the
 program is blocked until it becomes possible to read or write the file.
 You can have it not block in the flock function by defining environment variable
 CHAR_NONBLOCK.
 
 Example:
 
   SET CHAR_NONBLOCK=1
 
 (The value '1' doesn't have the meaning)

#if MACPERL =head1 MacJPerl on The MacOS

 The functions of MacJPerl was mimicked referring to the books and web.
 It is welcome if there is a bug report.
 
 The following software is necessary to execute Sjis software.
 1. MacPerl module
 2. Mac::Files module
 3. ToolServer
 4. MPW(Macintosh Programmer's Workshop)

#endif =head1 BUGS, LIMITATIONS, and COMPATIBILITY

I have tested and verified this software using the best of my ability. However, a software containing much regular expression is bound to contain some bugs. Thus, if you happen to find a bug that's in Sjis software and not your own program, you can try to reduce it to a minimal test case and then report it to the following author's address. If you have an idea that could make this a more useful tool, please let everyone share it.

  • (dummy item to avoid Test::Pod error)

    #if MULTIBYTE_ENCODING =item * format

    Function "format" can't handle multiple-octet code same as original Perl.

    #endif =item * cloister of regular expression

    The cloister (?s) and (?i) of a regular expression will not be implemented for the time being. Cloister (?s) can be substituted with the .(dot) and \N on /s modifier. Cloister (?i) can be substituted with \F...\E.

    #if ESCAPE_SECOND_OCTET =item * chdir

    Function chdir() can always be executed with perl5.005.

    There are the following limitations for DOS-like system(any of MSWin32, NetWare, symbian, dos).

    On perl5.006 or perl5.00800, if path is ended by chr(0x5C), it needs jacode.pl library.

    On perl5.008001 or later, perl5.010, perl5.012, perl5.014, perl5.016, perl5.018, perl5.020, perl5.022, perl5.024, perl5.026, perl5.028 if path is ended by chr(0x5C), chdir succeeds when a short path name (8dot3name) can be acquired according to COMMAND.COM or cmd.exe or Win95Cmd.exe. However, leaf-subdirectory of the current directory is a short path name (8dot3name).

      see also,
      Bug #81839
      chdir does not work with chr(0x5C) at end of path
      http://bugs.activestate.com/show_bug.cgi?id=81839

    #endif #if MULTIBYTE_ENCODING =item * Sjis::substr as Lvalue

    If Perl version is older than 5.14, Sjis::substr differs from CORE::substr, and cannot be used as a lvalue. To change part of a string, you need use the optional fourth argument which is the replacement string.

    Sjis::substr($string, 13, 4, "JPerl");

    #endif #if MULTIBYTE_ANCHORING =item * Special Variables $` and $& need /( Capture All )/

      Because $` and $& use $1.
    
      -------------------------------------------------------------------------------------------
      Before          After                Works as
      -------------------------------------------------------------------------------------------
      $`              Esjis::PREMATCH()    CORE::substr($&,0,CORE::length($&)-CORE::length($1))
      ${`}            Esjis::PREMATCH()    CORE::substr($&,0,CORE::length($&)-CORE::length($1))
      $PREMATCH       Esjis::PREMATCH()    CORE::substr($&,0,CORE::length($&)-CORE::length($1))
      ${^PREMATCH}    Esjis::PREMATCH()    CORE::substr($&,0,CORE::length($&)-CORE::length($1))
      $&              Esjis::MATCH()       $1
      ${&}            Esjis::MATCH()       $1
      $MATCH          Esjis::MATCH()       $1
      ${^MATCH}       Esjis::MATCH()       $1
      $'              $'                   $'
      ${'}            ${'}                 $'
      $POSTMATCH      Esjis::POSTMATCH()   $'
      ${^POSTMATCH}   Esjis::POSTMATCH()   $'
      -------------------------------------------------------------------------------------------
  • Limitation of Regular Expression

    This software has limitation from \G in multibyte anchoring. Only the following Perl can treat the character string which exceeds 32766 octets with a regular expression.

    perl 5.6 or later --- ActivePerl on MSWin32

    perl 5.10.1 or later --- other Perl

      see also,
      
      In 5.10.0, the * quantifier in patterns was sometimes treated as {0,32767}
      http://perldoc.perl.org/perl5101delta.html
      
      [perl #116379] \G can't treat over 32767 octet
      http://www.nntp.perl.org/group/perl.perl5.porters/2013/01/msg197320.html
      
      perlre - Perl regular expressions
      http://perldoc.perl.org/perlre.html
      
      perlre length limit
      http://stackoverflow.com/questions/4592467/perlre-length-limit
      
      Japanese Document
      Sjis/JA.pm

    #endif #if MULTIBYTE_ENCODING =item * Empty Variable in Regular Expression

    Unlike literal null string, an interpolated variable evaluated to the empty string can't use the most recent pattern from a previous successful regular expression.

  • Limitation of ?? and m??

    Multibyte character needs ( ) which is before {n,m}, {n,}, {n}, *, and + in ?? or m??. As a result, you need to rewrite a script about $1,$2,$3,... You cannot use (?: ) ?, {n,m}?, {n,}?, and {n}? in ?? and m??, because delimiter of m?? is '?'.

    #endif #if ESCAPE_SECOND_OCTET =item * Look-behind Assertion

    The look-behind assertion like (?<=[A-Z]) is not prevented from matching trail octet of the previous multiple-octet code.

    #endif =item * Modifier /a /d /l and /u of Regular Expression

    The concept of this software is not to use two or more encoding methods as literal string and literal of regexp in one Perl script. Therefore, modifier /a, /d, /l, and /u are not supported. \d means [0-9] universally.

  • Named Character

    A named character, such \N{GREEK SMALL LETTER EPSILON}, \N{greek:epsilon}, or \N{epsilon} is not supported.

  • Unicode Properties (aka Character Properties) of Regular Expression

    Unicode properties (aka character properties) of regexp are not available. Also (?[]) in regexp of Perl 5.18 is not available. There is no plans to currently support these.

    #if ESCAPE_SECOND_OCTET =item * ${^WIN32_SLOPPY_STAT} is ignored

    Even if ${^WIN32_SLOPPY_STAT} is set to a true value, file test functions Esjis::*(), Esjis::lstat(), and Esjis::stat() on Microsoft Windows open the file for the path which has chr(0x5c) at end.

    #endif =item * Delimiter of String and Regexp

    qq//, q//, qw//, qx//, qr//, m//, s///, tr///, and y/// can't use a wide character as the delimiter.

  • \b{...} Boundaries in Regular Expressions

    Following \b{...} available starting in v5.22 are not supported.

      \b{gcb} or \b{g}   Unicode "Grapheme Cluster Boundary"
      \b{sb}             Unicode "Sentence Boundary"
      \b{wb}             Unicode "Word Boundary"
      \B{gcb} or \B{g}   Unicode "Grapheme Cluster Boundary" doesn't match
      \B{sb}             Unicode "Sentence Boundary" doesn't match
      \B{wb}             Unicode "Word Boundary" doesn't match

AUTHOR

INABA Hitoshi <ina@cpan.org>

This project was originated by INABA Hitoshi.

LICENSE AND COPYRIGHT

This software is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My Goal

P.401 See chapter 15: Unicode of ISBN 0-596-00027-8 Programming Perl Third Edition.

Before the introduction of Unicode support in perl, The eq operator just compared the byte-strings represented by two scalars. Beginning with perl 5.8, eq compares two byte-strings with simultaneous consideration of the UTF8 flag.

/* You are not expected to understand this */

  Information processing model beginning with perl 5.8
 
    +----------------------+---------------------+
    |     Text strings     |                     |
    +----------+-----------|    Binary strings   |
    |  UTF-8   |  Latin-1  |                     |
    +----------+-----------+---------------------+
    | UTF8     |            Not UTF8             |
    | Flagged  |            Flagged              |
    +--------------------------------------------+
    http://perl-users.jp/articles/advent-calendar/2010/casual/4

  Confusion of Perl string model is made from double meanings of
  "Binary string."
  Meanings of "Binary string"
  1. Non-Text string
  2. Digital octet string

  Let's draw again using those term.
 
    +----------------------+---------------------+
    |     Text strings     |                     |
    +----------+-----------|   Non-Text strings  |
    |  UTF-8   |  Latin-1  |                     |
    +----------+-----------+---------------------+
    | UTF8     |            Not UTF8             |
    | Flagged  |            Flagged              |
    +--------------------------------------------+
    |            Digital octet string            |
    +--------------------------------------------+

There are people who don't agree to change in the character string processing model of Perl 5.8. It is impossible to get to agree it to majority of Perl user who hardly ever use Perl. How to solve it by returning to a original method, let's drag out page 402 of the old dusty Programming Perl, 3rd ed. again.

  Information processing model beginning with perl3 or this software
  of UNIX/C-ism.

    +--------------------------------------------+
    |    Text string as Digital octet string     |
    |    Digital octet string as Text string     |
    +--------------------------------------------+
    |       Not UTF8 Flagged, No Mojibake        |
    +--------------------------------------------+

  In UNIX Everything is a File
  - In UNIX everything is a stream of bytes
  - In UNIX the filesystem is used as a universal name space

  Native Encoding Scripting
  - native encoding of file contents
  - native encoding of file name on filesystem
  - native encoding of command line
  - native encoding of environment variable
  - native encoding of API
  - native encoding of network packet
  - native encoding of database

Ideally, I'd like to achieve these five Goals:

  • Goal #1:

    Old byte-oriented programs should not spontaneously break on the old byte-oriented data they used to work on.

    This goal has been achieved by that this software is additional code for perl like utf8 pragma. Perl should work same as past Perl if added nothing.

  • Goal #2:

    Old byte-oriented programs should magically start working on the new character-oriented data when appropriate.

    Still now, 1 octet is counted with 1 by built-in functions length, substr, index, rindex, and pos that handle length and position of string. In this part, there is no change. The length of 1 character of 2 octet code is 2.

    On the other hand, the regular expression in the script is added the multibyte anchoring processing with this software, instead of you.

    figure of Goal #1 and Goal #2.

                                   GOAL#1  GOAL#2
                            (a)     (b)     (c)     (d)     (e)
          +--------------+-------+-------+-------+-------+-------+
          | data         |  Old  |  Old  |  New  |  Old  |  New  |
          +--------------+-------+-------+-------+-------+-------+
          | script       |  Old  |      Old      |      New      |
          +--------------+-------+---------------+---------------+
          | interpreter  |  Old  |              New              |
          +--------------+-------+-------------------------------+
          Old --- Old byte-oriented
          New --- New character-oriented

    There is a combination from (a) to (e) in data, script, and interpreter of old and new. Let's add the Encode module and this software did not exist at time of be written this document and JPerl did exist.

                            (a)     (b)     (c)     (d)     (e)
                                          JPerl,japerl    Encode,Sjis
          +--------------+-------+-------+-------+-------+-------+
          | data         |  Old  |  Old  |  New  |  Old  |  New  |
          +--------------+-------+-------+-------+-------+-------+
          | script       |  Old  |      Old      |      New      |
          +--------------+-------+---------------+---------------+
          | interpreter  |  Old  |              New              |
          +--------------+-------+-------------------------------+
          Old --- Old byte-oriented
          New --- New character-oriented

    The reason why JPerl is very excellent is that it is at the position of (c). That is, it is not necessary to do a special description to the script to process new character-oriented string. (May the japerl take over JPerl!)

  • Goal #3:

    Programs should run just as fast in the new character-oriented mode as in the old byte-oriented mode.

    It is impossible. Because the following time is necessary.

    (1) Time of escape script for old byte-oriented perl.

    #if MULTIBYTE_ANCHORING (2) Time of processing regular expression by escaped script while multibyte anchoring.

    #endif Someday, I want to ask Larry Wall about this goal in the elevator.

  • Goal #4:

    Perl should remain one language, rather than forking into a byte-oriented Perl and a character-oriented Perl.

    JPerl remains one Perl language by forking to two interpreters. However, the Perl core team did not desire fork of the interpreter. As a result, Perl language forked contrary to goal #4.

    A character-oriented perl is not necessary to make it specially, because a byte-oriented perl can already treat the binary data. This software is only an application program of byte-oriented Perl, a filter program.

    And you will get support from the Perl community, when you solve the problem by the Perl script.

    Sjis software remains one language and one interpreter.

  • Goal #5:

    JPerl users will be able to maintain JPerl by Perl.

    May the JPerl be with you, always.

Back when Programming Perl, 3rd ed. was written, UTF8 flag was not born and Perl is designed to make the easy jobs easy. This software provides programming environment like at that time.

Perl's motto

   Some computer scientists (the reductionists, in particular) would
  like to deny it, but people have funny-shaped minds. Mental geography
  is not linear, and cannot be mapped onto a flat surface without
  severe distortion. But for the last score years or so, computer
  reductionists have been first bowing down at the Temple of Orthogonality,
  then rising up to preach their ideas of ascetic rectitude to any who
  would listen.
 
   Their fervent but misguided desire was simply to squash your mind to
  fit their mindset, to smush your patterns of thought into some sort of
  Hyperdimensional Flatland. It's a joyless existence, being smushed.
  --- Learning Perl on Win32 Systems

  If you think this is a big headache, you're right. No one likes
  this situation, but Perl does the best it can with the input and
  encodings it has to deal with. If only we could reset history and
  not make so many mistakes next time.
  --- Learning Perl 6th Edition

   The most important thing for most people to know about handling
  Unicode data in Perl, however, is that if you don't ever use any Uni-
  code data -- if none of your files are marked as UTF-8 and you don't
  use UTF-8 locales -- then you can happily pretend that you're back in
  Perl 5.005_03 land; the Unicode features will in no way interfere with
  your code unless you're explicitly using them. Sometimes the twin
  goals of embracing Unicode but not disturbing old-style byte-oriented
  scripts has led to compromise and confusion, but it's the Perl way to
  silently do the right thing, which is what Perl ends up doing.
  --- Advanced Perl Programming, 2nd Edition

SEE ALSO

 PERL PUROGURAMINGU
 Larry Wall, Randal L.Schwartz, Yoshiyuki Kondo
 December 1997
 ISBN 4-89052-384-7
 http://www.context.co.jp/~cond/books/old-books.html

 Programming Perl, Second Edition
 By Larry Wall, Tom Christiansen, Randal L. Schwartz
 October 1996
 Pages: 670
 ISBN 10: 1-56592-149-6 | ISBN 13: 9781565921498
 http://shop.oreilly.com/product/9781565921498.do

 Programming Perl, Third Edition
 By Larry Wall, Tom Christiansen, Jon Orwant
 Third Edition  July 2000
 Pages: 1104
 ISBN 10: 0-596-00027-8 | ISBN 13: 9780596000271
 http://shop.oreilly.com/product/9780596000271.do

 The Perl Language Reference Manual (for Perl version 5.12.1)
 by Larry Wall and others
 Paperback (6"x9"), 724 pages
 Retail Price: $39.95 (pound 29.95 in UK)
 ISBN-13: 978-1-906966-02-7
 http://www.network-theory.co.uk/perl/language/

 Perl Pocket Reference, 5th Edition
 By Johan Vromans
 Publisher: O'Reilly Media
 Released: July 2011
 Pages: 102
 http://shop.oreilly.com/product/0636920018476.do

 Programming Perl, 4th Edition
 By: Tom Christiansen, brian d foy, Larry Wall, Jon Orwant
 Publisher: O'Reilly Media
 Formats: Print, Ebook, Safari Books Online
 Released: March 2012
 Pages: 1130
 Print ISBN: 978-0-596-00492-7 | ISBN 10: 0-596-00492-3
 Ebook ISBN: 978-1-4493-9890-3 | ISBN 10: 1-4493-9890-1
 http://shop.oreilly.com/product/9780596004927.do

 Perl Cookbook
 By Tom Christiansen, Nathan Torkington
 August 1998
 Pages: 800
 ISBN 10: 1-56592-243-3 | ISBN 13: 978-1-56592-243-3
 http://shop.oreilly.com/product/9781565922433.do

 Perl Cookbook, Second Edition
 By Tom Christiansen, Nathan Torkington
 Second Edition  August 2003
 Pages: 964
 ISBN 10: 0-596-00313-7 | ISBN 13: 9780596003135
 http://shop.oreilly.com/product/9780596003135.do

 Perl in a Nutshell, Second Edition
 By Stephen Spainhour, Ellen Siever, Nathan Patwardhan
 Second Edition  June 2002
 Pages: 760
 Series: In a Nutshell
 ISBN 10: 0-596-00241-6 | ISBN 13: 9780596002411
 http://shop.oreilly.com/product/9780596002411.do

 Learning Perl on Win32 Systems
 By Randal L. Schwartz, Erik Olson, Tom Christiansen
 August 1997
 Pages: 306
 ISBN 10: 1-56592-324-3 | ISBN 13: 9781565923249
 http://shop.oreilly.com/product/9781565923249.do

 Learning Perl, Fifth Edition
 By Randal L. Schwartz, Tom Phoenix, brian d foy
 June 2008
 Pages: 352
 Print ISBN:978-0-596-52010-6 | ISBN 10: 0-596-52010-7
 Ebook ISBN:978-0-596-10316-3 | ISBN 10: 0-596-10316-6
 http://shop.oreilly.com/product/9780596520113.do

 Learning Perl, 6th Edition
 By Randal L. Schwartz, brian d foy, Tom Phoenix
 June 2011
 Pages: 390
 ISBN-10: 1449303587 | ISBN-13: 978-1449303587
 http://shop.oreilly.com/product/0636920018452.do

 Advanced Perl Programming, 2nd Edition
 By Simon Cozens
 June 2005
 Pages: 300
 ISBN-10: 0-596-00456-7 | ISBN-13: 978-0-596-00456-9
 http://shop.oreilly.com/product/9780596004569.do

 Perl RESOURCE KIT UNIX EDITION
 Futato, Irving, Jepson, Patwardhan, Siever
 ISBN 10: 1-56592-370-7
 http://shop.oreilly.com/product/9781565923706.do

 Perl Resource Kit -- Win32 Edition
 Erik Olson, Brian Jepson, David Futato, Dick Hardt
 ISBN 10:1-56592-409-6
 http://shop.oreilly.com/product/9781565924093.do

 MODAN Perl NYUMON
 By Daisuke Maki
 2009/2/10
 Pages: 344
 ISBN 10: 4798119172 | ISBN 13: 978-4798119175
 http://www.seshop.com/product/detail/10250/

 Understanding Japanese Information Processing
 By Ken Lunde
 January 1900
 Pages: 470
 ISBN 10: 1-56592-043-0 | ISBN 13: 9781565920439
 http://shop.oreilly.com/product/9781565920439.do

 CJKV Information Processing
 Chinese, Japanese, Korean & Vietnamese Computing
 By Ken Lunde
 First Edition  January 1999
 Pages: 1128
 ISBN 10: 1-56592-224-7 | ISBN 13: 9781565922242
 http://shop.oreilly.com/product/9781565922242.do

 Mastering Regular Expressions, Second Edition
 By Jeffrey E. F. Friedl
 Second Edition  July 2002
 Pages: 484
 ISBN 10: 0-596-00289-0 | ISBN 13: 9780596002893
 http://shop.oreilly.com/product/9780596002893.do

 Mastering Regular Expressions, Third Edition
 By Jeffrey E. F. Friedl
 Third Edition  August 2006
 Pages: 542
 ISBN 10: 0-596-52812-4 | ISBN 13:9780596528126
 http://shop.oreilly.com/product/9780596528126.do

 Regular Expressions Cookbook
 By Jan Goyvaerts, Steven Levithan
 May 2009
 Pages: 512
 ISBN 10:0-596-52068-9 | ISBN 13: 978-0-596-52068-7
 http://shop.oreilly.com/product/9780596520694.do

 Regular Expressions Cookbook, 2nd Edition
 By Jan Goyvaerts, Steven Levithan
 Final Release Date: August 2012
 Pages: 612
 ISBN: 978-1-4493-1943-4 | ISBN 10:1-4493-1943-2

 JIS KANJI JITEN
 By Kouji Shibano
 Pages: 1456
 ISBN 4-542-20129-5
 http://www.webstore.jsa.or.jp/lib/lib.asp?fn=/manual/mnl01_12.htm

 UNIX MAGAZINE
 1993 Aug
 Pages: 172
 T1008901080816 ZASSHI 08901-8
 http://ascii.asciimw.jp/books/books/detail/978-4-7561-5008-0.shtml

 LINUX NIHONGO KANKYO
 By YAMAGATA Hiroo, Stephen J. Turnbull, Craig Oda, Robert J. Bickel
 June, 2000
 Pages: 376
 ISBN 4-87311-016-5
 http://www.oreilly.co.jp/books/4873110165/

 MacPerl Power and Ease
 By Vicki Brown, Chris Nandor
 April 1998
 Pages: 350
 ISBN 10: 1881957322 | ISBN 13: 978-1881957324
 http://www.amazon.com/Macperl-Power-Ease-Vicki-Brown/dp/1881957322

 Windows NT Shell Scripting
 By Timothy Hill
 April 27, 1998
 Pages: 400
 ISBN 10: 1578700477 | ISBN 13: 9781578700479
 http://search.barnesandnoble.com/Windows-NT-Shell-Scripting/Timothy-Hill/e/9781578700479/

 Windows(R) Command-Line Administrators Pocket Consultant, 2nd Edition
 By William R. Stanek
 February 2009
 Pages: 594
 ISBN 10: 0-7356-2262-0 | ISBN 13: 978-0-7356-2262-3
 http://shop.oreilly.com/product/9780735622623.do

 Kaoru Maeda, Perl's history Perl 1,2,3,4
 http://www.slideshare.net/KaoruMaeda/perl-perl-1234

 nurse, What is "string"
 http://d.hatena.ne.jp/nurse/20141107#1415355181

 NISHIO Hirokazu, What's meant "string as a sequence of characters"?
 http://d.hatena.ne.jp/nishiohirokazu/20141107/1415286729

 nurse, History of Japanese EUC 22:00
 http://d.hatena.ne.jp/nurse/20090308/1236517235

 Mike Whitaker, Perl And Unicode
 http://www.slideshare.net/Penfold/perl-and-unicode

 Ricardo Signes, Perl 5.14 for Pragmatists
 http://www.slideshare.net/rjbs/perl-514-8809465

 Ricardo Signes, What's New in Perl? v5.10 - v5.16 #'
 http://www.slideshare.net/rjbs/whats-new-in-perl-v510-v516

 YAP(achimon)C::Asia Hachioji 2016 mid in Shinagawa
 Kenichi Ishigaki (@charsbar) July 3, 2016 YAP(achimon)C::Asia Hachioji 2016mid
 https://www.slideshare.net/charsbar/cpan-63708689

 CPAN Directory INABA Hitoshi
 http://search.cpan.org/~ina/

 BackPAN
 http://backpan.perl.org/authors/id/I/IN/INA/

 Recent Perl packages by "INABA Hitoshi"
 http://code.activestate.com/ppm/author:INABA-Hitoshi/

ACKNOWLEDGEMENTS

This software was made referring to software and the document that the following hackers or persons had made. I am thankful to all persons.

 Rick Yamashita, Shift_JIS
 ttp://furukawablog.spaces.live.com/Blog/cns!1pmWgsL289nm7Shn7cS0jHzA!2225.entry (dead link)
 ttp://shino.tumblr.com/post/116166805/1981-us-jis
 (add 'h' at head)
 http://www.wdic.org/w/WDIC/%E3%82%B7%E3%83%95%E3%83%88JIS

 Larry Wall, Perl
 http://www.perl.org/

 Kazumasa Utashiro, jcode.pl
 http://search.cpan.org/~utashiro/
 ftp://ftp.iij.ad.jp/pub/IIJ/dist/utashiro/perl/
 http://log.utashiro.com/pub/2006/07/jkondo_a580.html

 Jeffrey E. F. Friedl, Mastering Regular Expressions
 http://regex.info/

 SADAHIRO Tomoyuki, The right way of using Shift_JIS
 http://homepage1.nifty.com/nomenclator/perl/shiftjis.htm
 http://search.cpan.org/~sadahiro/

 Yukihiro "Matz" Matsumoto, YAPC::Asia2006 Ruby on Perl(s)
 http://www.rubyist.net/~matz/slides/yapc2006/

 jscripter, For jperl users
 http://homepage1.nifty.com/kazuf/jperl.html

 Bruce., Unicode in Perl
 http://www.rakunet.org/tsnet/TSabc/18/546.html

 Hiroaki Izumi, Perl5.8/Perl5.10 is not useful on the Windows.
 http://dl.dropbox.com/u/23756062/perlwin.html
 https://sites.google.com/site/hiroa63iz/perlwin

 TSUKAMOTO Makio, Perl memo/file path of Windows
 http://digit.que.ne.jp/work/wiki.cgi?Perl%E3%83%A1%E3%83%A2%2FWindows%E3%81%A7%E3%81%AE%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%83%91%E3%82%B9

 chaichanPaPa, Matching Shift_JIS file name
 http://d.hatena.ne.jp/chaichanPaPa/20080802/1217660826

 SUZUKI Norio, Jperl
 http://homepage2.nifty.com/kipp/perl/jperl/

 WATANABE Hirofumi, Jperl
 http://www.cpan.org/src/5.0/jperl/
 http://search.cpan.org/~watanabe/
 ftp://ftp.oreilly.co.jp/pcjp98/watanabe/jperlconf.ppt

 Chuck Houpt, Michiko Nozu, MacJPerl
 http://habilis.net/macjperl/index.j.html

 Kenichi Ishigaki, Pod-PerldocJp, Welcome to modern Perl world
 http://search.cpan.org/dist/Pod-PerldocJp/
 http://gihyo.jp/dev/serial/01/modern-perl/0031
 http://gihyo.jp/dev/serial/01/modern-perl/0032
 http://gihyo.jp/dev/serial/01/modern-perl/0033

 Fuji, Goro (gfx), Perl Hackers Hub No.16
 http://gihyo.jp/dev/serial/01/perl-hackers-hub/001602

 Dan Kogai, Encode module
 http://search.cpan.org/dist/Encode/
 http://www.archive.org/details/YAPCAsia2006TokyoPerl58andUnicodeMythsFactsandChanges (video)
 http://yapc.g.hatena.ne.jp/jkondo/ (audio)

 Takahashi Masatuyo, JPerl Wiki
 http://ja.jperl.wikia.com/wiki/JPerl_Wiki

 Juerd, Perl Unicode Advice
 http://juerd.nl/site.plp/perluniadvice

 daily dayflower, 2008-06-25 perluniadvice
 http://d.hatena.ne.jp/dayflower/20080625/1214374293

 Unicode issues in Perl
 http://www.i-programmer.info/programming/other-languages/1973-unicode-issues-in-perl.html

 Jesse Vincent, Compatibility is a virtue
 http://www.nntp.perl.org/group/perl.perl5.porters/2010/05/msg159825.html

 Tokyo-pm archive
 http://mail.pm.org/pipermail/tokyo-pm/
 http://mail.pm.org/pipermail/tokyo-pm/1999-September/001844.html
 http://mail.pm.org/pipermail/tokyo-pm/1999-September/001854.html

 Error: Runtime exception on jperl 5.005_03
 http://www.rakunet.org/tsnet/TSperl/12/374.html
 http://www.rakunet.org/tsnet/TSperl/12/375.html
 http://www.rakunet.org/tsnet/TSperl/12/376.html
 http://www.rakunet.org/tsnet/TSperl/12/377.html
 http://www.rakunet.org/tsnet/TSperl/12/378.html
 http://www.rakunet.org/tsnet/TSperl/12/379.html
 http://www.rakunet.org/tsnet/TSperl/12/380.html
 http://www.rakunet.org/tsnet/TSperl/12/382.html

 ruby-list
 http://blade.nagaokaut.ac.jp/ruby/ruby-list/index.shtml
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/2440
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/2446
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/2569
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/9427
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/9431
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/10500
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/10501
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/10502
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/12385
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/12392
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/12393
 http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/19156

 Object-oriented with Perl
 http://www.freeml.com/perl-oo/486
 http://www.freeml.com/perl-oo/487
 http://www.freeml.com/perl-oo/490
 http://www.freeml.com/perl-oo/491
 http://www.freeml.com/perl-oo/492
 http://www.freeml.com/perl-oo/494
 http://www.freeml.com/perl-oo/514

NAME

Esjis - Run-time routines for Sjis.pm

SYNOPSIS

  use Esjis;

    Esjis::split(...);
    Esjis::tr(...);
    Esjis::chop(...);
    Esjis::index(...);
    Esjis::rindex(...);
    Esjis::lc(...);
    Esjis::lc_;
    Esjis::lcfirst(...);
    Esjis::lcfirst_;
    Esjis::uc(...);
    Esjis::uc_;
    Esjis::ucfirst(...);
    Esjis::ucfirst_;
    Esjis::fc(...);
    Esjis::fc_;
    Esjis::ignorecase(...);
    Esjis::capture(...);
    Esjis::chr(...);
    Esjis::chr_;
#if ESCAPE_SECOND_OCTET
    Esjis::X ...;
    Esjis::X_;
#endif
    Esjis::glob(...);
    Esjis::glob_;
#if ESCAPE_SECOND_OCTET
    Esjis::lstat(...);
    Esjis::lstat_;
    Esjis::opendir(...);
    Esjis::stat(...);
    Esjis::stat_;
    Esjis::unlink(...);
    Esjis::chdir(...);
    Esjis::do(...);
    Esjis::require(...);
    Esjis::telldir(...);
#endif

  # "no Esjis;" not supported

ABSTRACT

This module has run-time routines for use Sjis software automatically, you do not have to use.

BUGS AND LIMITATIONS

I have tested and verified this software using the best of my ability. However, a software containing much regular expression is bound to contain some bugs. Thus, if you happen to find a bug that's in Sjis software and not your own program, you can try to reduce it to a minimal test case and then report it to the following author's address. If you have an idea that could make this a more useful tool, please let everyone share it.

HISTORY

This Esjis module first appeared in ActivePerl Build 522 Built under MSWin32 Compiled at Nov 2 1999 09:52:28

AUTHOR

INABA Hitoshi <ina@cpan.org>

This project was originated by INABA Hitoshi. For any questions, use <ina@cpan.org> so we can share this file.

LICENSE AND COPYRIGHT

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

EXAMPLES

  • Split string

      @split = Esjis::split(/pattern/,$string,$limit);
      @split = Esjis::split(/pattern/,$string);
      @split = Esjis::split(/pattern/);
      @split = Esjis::split('',$string,$limit);
      @split = Esjis::split('',$string);
      @split = Esjis::split('');
      @split = Esjis::split();
      @split = Esjis::split;
    
      This subroutine scans a string given by $string for separators, and splits the
      string into a list of substring, returning the resulting list value in list
      context or the count of substring in scalar context. Scalar context also causes
      split to write its result to @_, but this usage is deprecated. The separators
      are determined by repeated pattern matching, using the regular expression given
      in /pattern/, so the separators may be of any size and need not be the same
      string on every match. (The separators are not ordinarily returned; exceptions
      are discussed later in this section.) If the /pattern/ doesn't match the string
      at all, Esjis::split returns the original string as a single substring, If it
      matches once, you get two substrings, and so on. You may supply regular
      expression modifiers to the /pattern/, like /pattern/i, /pattern/x, etc. The
      //m modifier is assumed when you split on the pattern /^/.
    
      If $limit is specified and positive, the subroutine splits into no more than that
      many fields (though it may split into fewer if it runs out of separators). If
      $limit is negative, it is treated as if an arbitrarily large $limit has been
      specified If $limit is omitted or zero, trailing null fields are stripped from
      the result (which potential users of pop would do wel to remember). If $string
      is omitted, the subroutine splits the $_ string. If /pattern/ is also omitted or
      is the literal space, " ", the subroutine split on whitespace, /\s+/, after
      skipping any leading whitespace.
    
      A /pattern/ of /^/ is secretly treated if it it were /^/m, since it isn't much
      use otherwise.
    
      String of any length can be split:
    
      @chars  = Esjis::split(//,  $word);
      @fields = Esjis::split(/:/, $line);
      @words  = Esjis::split(" ", $paragraph);
      @lines  = Esjis::split(/^/, $buffer);
    
      A pattern capable of matching either the null string or something longer than
      the null string (for instance, a pattern consisting of any single character
      modified by a * or ?) will split the value of $string into separate characters
      wherever it matches the null string between characters; nonnull matches will
      skip over the matched separator characters in the usual fashion. (In other words,
      a pattern won't match in one spot more than once, even if it matched with a zero
      width.) For example:
    
      print join(":" => Esjis::split(/ */, "hi there"));
    
      produces the output "h:i:t:h:e:r:e". The space disappers because it matches
      as part of the separator. As a trivial case, the null pattern // simply splits
      into separate characters, and spaces do not disappear. (For normal pattern
      matches, a // pattern would repeat the last successfully matched pattern, but
      Esjis::split's pattern is exempt from that wrinkle.)
    
      The $limit parameter splits only part of a string:
    
      my ($login, $passwd, $remainder) = Esjis::split(/:/, $_, 3);
    
      We encourage you to split to lists of names like this to make your code
      self-documenting. (For purposes of error checking, note that $remainder would
      be undefined if there were fewer than three fields.) When assigning to a list,
      if $limit is omitted, Perl supplies a $limit one larger than the number of
      variables in the list, to avoid unneccessary work. For the split above, $limit
      would have been 4 by default, and $remainder would have received only the third
      field, not all the rest of the fields. In time-critical applications, it behooves
      you not to split into more fields than you really need. (The trouble with
      powerful languages it that they let you be powerfully stupid at times.)
    
      We said earlier that the separators are not returned, but if the /pattern/
      contains parentheses, then the substring matched by each pair of parentheses is
      included in the resulting list, interspersed with the fields that are ordinarily
      returned. Here's a simple example:
    
      Esjis::split(/([-,])/, "1-10,20");
    
      which produces the list value:
    
      (1, "-", 10, ",", 20)
    
      With more parentheses, a field is returned for each pair, even if some pairs
      don't match, in which case undefined values are returned in those positions. So
      if you say:
    
      Esjis::split(/(-)|(,)/, "1-10,20");
    
      you get the value:
    
      (1, "-", undef, 10, undef, ",", 20)
    
      The /pattern/ argument may be replaced with an expression to specify patterns
      that vary at runtime. As with ordinary patterns, to do run-time compilation only
      once, use /$variable/o.
    
      As a special case, if the expression is a single space (" "), the subroutine
      splits on whitespace just as Esjis::split with no arguments does. Thus,
      Esjis::split(" ") can be used to emulate awk's default behavior. In contrast,
      Esjis::split(/ /) will give you as many null initial fields as there are
      leading spaces. (Other than this special case, if you supply a string instead
      of a regular expression, it'll be interpreted as a regular expression anyway.)
      You can use this property to remove leading and trailing whitespace from a
      string and to collapse intervaning stretches of whitespace into a single
      space:
    
      $string = join(" ", Esjis::split(" ", $string));
    
      The following example splits an RFC822 message header into a hash containing
      $head{'Date'}, $head{'Subject'}, and so on. It uses the trick of assigning a
      list of pairs to a hash, because separators altinate with separated fields, It
      users parentheses to return part of each separator as part of the returned list
      value. Since the split pattern is guaranteed to return things in pairs by virtue
      of containing one set of parentheses, the hash assignment is guaranteed to
      receive a list consisting of key/value pairs, where each key is the name of a
      header field. (Unfortunately, this technique loses information for multiple lines
      with the same key field, such as Received-By lines. Ah well)
    
      $header =~ s/\n\s+/ /g; # Merge continuation lines.
      %head = ("FRONTSTUFF", Esjis::split(/^(\S*?):\s*/m, $header));
    
      The following example processes the entries in a Unix passwd(5) file. You could
      leave out the chomp, in which case $shell would have a newline on the end of it.
    
      open(PASSWD, "/etc/passwd");
      while (<PASSWD>) {
          chomp; # remove trailing newline.
          ($login, $passwd, $uid, $gid, $gcos, $home, $shell) =
              Esjis::split(/:/);
          ...
      }
    
      Here's how process each word of each line of each file of input to create a
      word-frequency hash.
    
      while (<>) {
          for my $word (Esjis::split()) {
              $count{$word}++;
          }
      }
    
      The inverse of Esjis::split is join, except that join can only join with the
      same separator between all fields. To break apart a string with fixed-position
      fields, use unpack.
    
      Processing long $string (over 32766 octets) requires Perl 5.010001 or later.
  • Transliteration

      $tr = Esjis::tr($variable,$bind_operator,$searchlist,$replacementlist,$modifier);
      $tr = Esjis::tr($variable,$bind_operator,$searchlist,$replacementlist);
    
      This is the transliteration (sometimes erroneously called translation) operator,
      which is like the y/// operator in the Unix sed program, only better, in
      everybody's humble opinion.
    
      This subroutine scans a ShiftJIS string character by character and replaces all
      occurrences of the characters found in $searchlist with the corresponding character
      in $replacementlist. It returns the number of characters replaced or deleted.
      If no ShiftJIS string is specified via =~ operator, the $_ variable is translated.
      $modifier are:
    
      ---------------------------------------------------------------------------
      Modifier   Meaning
      ---------------------------------------------------------------------------
      c          Complement $searchlist.
      d          Delete found but unreplaced characters.
      s          Squash duplicate replaced characters.
      r          Return transliteration and leave the original string untouched.
      ---------------------------------------------------------------------------
    
      To use with a read-only value without raising an exception, use the /r modifier.
    
      print Esjis::tr('bookkeeper','=~','boep','peob','r'); # prints 'peekkoobor'
  • Chop string

      $chop = Esjis::chop(@list);
      $chop = Esjis::chop();
      $chop = Esjis::chop;
    
      This subroutine chops off the last character of a string variable and returns the
      character chopped. The Esjis::chop subroutine is used primary to remove the newline
      from the end of an input recoed, and it is more efficient than using a
      substitution. If that's all you're doing, then it would be safer to use chomp,
      since Esjis::chop always shortens the string no matter what's there, and chomp
      is more selective. If no argument is given, the subroutine chops the $_ variable.
    
      You cannot Esjis::chop a literal, only a variable. If you Esjis::chop a list of
      variables, each string in the list is chopped:
    
      @lines = `cat myfile`;
      Esjis::chop(@lines);
    
      You can Esjis::chop anything that is an lvalue, including an assignment:
    
      Esjis::chop($cwd = `pwd`);
      Esjis::chop($answer = <STDIN>);
    
      This is different from:
    
      $answer = Esjis::chop($tmp = <STDIN>); # WRONG
    
      which puts a newline into $answer because Esjis::chop returns the character
      chopped, not the remaining string (which is in $tmp). One way to get the result
      intended here is with substr:
    
      $answer = substr <STDIN>, 0, -1;
    
      But this is more commonly written as:
    
      Esjis::chop($answer = <STDIN>);
    
      In the most general case, Esjis::chop can be expressed using substr:
    
      $last_code = Esjis::chop($var);
      $last_code = substr($var, -1, 1, ""); # same thing
    
      Once you understand this equivalence, you can use it to do bigger chops. To
      Esjis::chop more than one character, use substr as an lvalue, assigning a null
      string. The following removes the last five characters of $caravan:
    
      substr($caravan, -5) = '';
    
      The negative subscript causes substr to count from the end of the string instead
      of the beginning. To save the removed characters, you could use the four-argument
      form of substr, creating something of a quintuple Esjis::chop;
    
      $tail = substr($caravan, -5, 5, '');
    
      This is all dangerous business dealing with characters instead of graphemes. Perl
      doesn't really have a grapheme mode, so you have to deal with them yourself.
  • Index string

      $byte_pos = Esjis::index($string,$substr,$byte_offset);
      $byte_pos = Esjis::index($string,$substr);
    
      This subroutine searches for one string within another. It returns the byte position
      of the first occurrence of $substring in $string. The $byte_offset, if specified,
      says how many bytes from the start to skip before beginning to look. Positions are
      based at 0. If the substring is not found, the subroutine returns one less than the
      base, ordinarily -1. To work your way through a string, you might say:
    
      $byte_pos = -1;
      while (($byte_pos = Esjis::index($string, $lookfor, $byte_pos)) > -1) {
          print "Found at $byte_pos\n";
          $byte_pos++;
      }
  • Reverse index string

      $byte_pos = Esjis::rindex($string,$substr,$byte_offset);
      $byte_pos = Esjis::rindex($string,$substr);
    
      This subroutine works just like Esjis::index except that it returns the byte
      position of the last occurrence of $substring in $string (a reverse Esjis::index).
      The subroutine returns -1 if $substring is not found. $byte_offset, if specified,
      is the rightmost byte position that may be returned. To work your way through a
      string backward, say:
    
      $byte_pos = length($string);
      while (($byte_pos = Sjis::rindex($string, $lookfor, $byte_pos)) >= 0) {
          print "Found at $byte_pos\n";
          $byte_pos--;
      }
  • Lower case string

      $lc = Esjis::lc($string);
      $lc = Esjis::lc_;
    
      This subroutine returns a lowercased version of ShiftJIS $string (or $_, if
      $string is omitted). This is the internal subroutine implementing the \L escape
      in double-quoted strings.
    
      You can use the Esjis::fc subroutine for case-insensitive comparisons via Sjis
      software.
  • Lower case first character of string

      $lcfirst = Esjis::lcfirst($string);
      $lcfirst = Esjis::lcfirst_;
    
      This subroutine returns a version of ShiftJIS $string with the first character
      lowercased (or $_, if $string is omitted). This is the internal subroutine
      implementing the \l escape in double-quoted strings.
  • Upper case string

      $uc = Esjis::uc($string);
      $uc = Esjis::uc_;
    
      This subroutine returns an uppercased version of ShiftJIS $string (or $_, if
      $string is omitted). This is the internal subroutine implementing the \U escape
      in interpolated strings. For titlecase, use Esjis::ucfirst instead.
    
      You can use the Esjis::fc subroutine for case-insensitive comparisons via Sjis
      software.
  • Upper case first character of string

      $ucfirst = Esjis::ucfirst($string);
      $ucfirst = Esjis::ucfirst_;
    
      This subroutine returns a version of ShiftJIS $string with the first character
      titlecased and other characters left alone (or $_, if $string is omitted).
      Titlecase is "Camel" for an initial capital that has (or expects to have)
      lowercase characters following it, not uppercase ones. Exsamples are the first
      letter of a sentence, of a person's name, of a newspaper headline, or of most
      words in a title. Characters with no titlecase mapping return the uppercase
      mapping instead. This is the internal subroutine implementing the \u escape in
      double-quoted strings.
    
      To capitalize a string by mapping its first character to titlecase and the rest
      to lowercase, use:
    
      $titlecase = Esjis::ucfirst(substr($word,0,1)) . Esjis::lc(substr($word,1));
    
      or
    
      $string =~ s/(\w)((?>\w*))/\u$1\L$2/g;
    
      Do not use:
    
      $do_not_use = Esjis::ucfirst(Esjis::lc($word));
    
      or "\u\L$word", because that can produce a different and incorrect answer with
      certain characters. The titlecase of something that's been lowercased doesn't
      always produce the same thing titlecasing the original produces.
    
      Because titlecasing only makes sense at the start of a string that's followed
      by lowercase characters, we can't think of any reason you might want to titlecase
      every character in a string.
    
      See also P.287 A Case of Mistaken Identity
      in Chapter 6: Unicode
      of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
  • Fold case string

      P.860 fc
      in Chapter 27: Functions
      of ISBN 978-0-596-00492-7 Programming Perl 4th Edition.
    
      $fc = Esjis::fc($string);
      $fc = Esjis::fc_;
    
      New to Sjis software, this subroutine returns the full Unicode-like casefold of
      ShiftJIS $string (or $_, if omitted). This is the internal subroutine implementing
      the \F escape in double-quoted strings.
    
      Just as title-case is based on uppercase but different, foldcase is based on
      lowercase but different. In ASCII there is a one-to-one mapping between only
      two cases, but in other encoding there is a one-to-many mapping and between three
      cases. Because that's too many combinations to check manually each time, a fourth
      casemap called foldcase was invented as a common intermediary for the other three.
      It is not a case itself, but it is a casemap.
    
      To compare whether two strings are the same without regard to case, do this:
    
      Esjis::fc($a) eq Esjis::fc($b)
    
      The reliable way to compare string case-insensitively was with the /i pattern
      modifier, because Sjis software has always used casefolding semantics for
      case-insensitive pattern matches. Knowing this, you can emulate equality
      comparisons like this:
    
      sub fc_eq ($$) {
          my($a,$b) = @_;
          return $a =~ /\A\Q$b\E\z/i;
      }
  • Make ignore case string

      @ignorecase = Esjis::ignorecase(@string);
    
      This subroutine is internal use to m/ /i, s/ / /i, split / /i, and qr/ /i.
  • Make capture number

      $capturenumber = Esjis::capture($string);
    
      This subroutine is internal use to m/ /, s/ / /, split / /, and qr/ /.
  • Make character

      $chr = Esjis::chr($code);
      $chr = Esjis::chr_;
    
      This subroutine returns a programmer-visible character, character represented by
      that $code in the character set. For example, Esjis::chr(65) is "A" in either
      ASCII or ShiftJIS, not Unicode. For the reverse of Esjis::chr, use Sjis::ord.

    #if ESCAPE_SECOND_OCTET =item * File test subroutine Esjis::X

      The following all subroutines function when the pathname ends with chr(0x5C) on
      MSWin32.
    
      A file test subroutine is a unary function that takes one argument, either a
      filename or a filehandle, and tests the associated file to see whether something
      is true about it. If the argument is omitted, it tests $_. Unless otherwise
      documented, it returns 1 for true and "" for false, or the undefined value if
      the file doesn't exist or is otherwise inaccessible. Currently implemented file
      test subroutines are listed in:
    
      Available in MSWin32, MacOS, and UNIX-like systems
      ------------------------------------------------------------------------------
      Subroutine and Prototype   Meaning
      ------------------------------------------------------------------------------
      Esjis::r(*), Esjis::r_()   File or directory is readable by this (effective) user or group
      Esjis::w(*), Esjis::w_()   File or directory is writable by this (effective) user or group
      Esjis::e(*), Esjis::e_()   File or directory name exists
      Esjis::x(*), Esjis::x_()   File or directory is executable by this (effective) user or group
      Esjis::z(*), Esjis::z_()   File exists and has zero size (always false for directories)
      Esjis::f(*), Esjis::f_()   Entry is a plain file
      Esjis::d(*), Esjis::d_()   Entry is a directory
      ------------------------------------------------------------------------------
      
      Available in MacOS and UNIX-like systems
      ------------------------------------------------------------------------------
      Subroutine and Prototype   Meaning
      ------------------------------------------------------------------------------
      Esjis::R(*), Esjis::R_()   File or directory is readable by this real user or group
                                 Same as Esjis::r(*), Esjis::r_() on MacOS
      Esjis::W(*), Esjis::W_()   File or directory is writable by this real user or group
                                 Same as Esjis::w(*), Esjis::w_() on MacOS
      Esjis::X(*), Esjis::X_()   File or directory is executable by this real user or group
                                 Same as Esjis::x(*), Esjis::x_() on MacOS
      Esjis::l(*), Esjis::l_()   Entry is a symbolic link
      Esjis::S(*), Esjis::S_()   Entry is a socket
      ------------------------------------------------------------------------------
      
      Not available in MSWin32 and MacOS
      ------------------------------------------------------------------------------
      Subroutine and Prototype   Meaning
      ------------------------------------------------------------------------------
      Esjis::o(*), Esjis::o_()   File or directory is owned by this (effective) user
      Esjis::O(*), Esjis::O_()   File or directory is owned by this real user
      Esjis::p(*), Esjis::p_()   Entry is a named pipe (a "fifo")
      Esjis::b(*), Esjis::b_()   Entry is a block-special file (like a mountable disk)
      Esjis::c(*), Esjis::c_()   Entry is a character-special file (like an I/O device)
      Esjis::u(*), Esjis::u_()   File or directory is setuid
      Esjis::g(*), Esjis::g_()   File or directory is setgid
      Esjis::k(*), Esjis::k_()   File or directory has the sticky bit set
      ------------------------------------------------------------------------------
    
      The tests -T and -B takes a try at telling whether a file is text or binary.
      But people who know a lot about filesystems know that there's no bit (at least
      in UNIX-like operating systems) to indicate that a file is a binary or text file
      --- so how can Perl tell?
      The answer is that Perl cheats. As you might guess, it sometimes guesses wrong.
    
      This incomplete thinking of file test operator -T and -B gave birth to UTF8 flag
      of a later period.
    
      The Esjis::T, Esjis::T_, Esjis::B, and Esjis::B_ work as follows. The first block
      or so of the file is examined for strange chatracters such as
      [\000-\007\013\016-\032\034-\037\377] (that don't look like ShiftJIS). If more
      than 10% of the bytes appear to be strange, it's a *maybe* binary file;
      otherwise, it's a *maybe* text file. Also, any file containing ASCII NUL(\0) or
      \377 in the first block is considered a binary file. If Esjis::T or Esjis::B is
      used on a filehandle, the current input (standard I/O or "stdio") buffer is
      examined rather than the first block of the file. Both Esjis::T and Esjis::B
      return 1 as true on an empty file, or on a file at EOF (end-of-file) when testing
      a filehandle. Both Esjis::T and Esjis::B doesn't work when given the special
      filehandle consisting of a solitary underline. Because Esjis::T has to read to
      do the test, you don't want to use Esjis::T on special files that might hang or
      give you other kinds or grief. So on most occasions you'll want to test with a
      Esjis::f first, as in:
    
      next unless Esjis::f($file) && Esjis::T($file);
    
      Available in MSWin32, MacOS, and UNIX-like systems
      ------------------------------------------------------------------------------
      Subroutine and Prototype   Meaning
      ------------------------------------------------------------------------------
      Esjis::T(*), Esjis::T_()   File looks like a "text" file
      Esjis::B(*), Esjis::B_()   File looks like a "binary" file
      ------------------------------------------------------------------------------
    
      File ages for Esjis::M, Esjis::M_, Esjis::A, Esjis::A_, Esjis::C, and Esjis::C_
      are returned in days (including fractional days) since the script started running.
      This start time is stored in the special variable $^T ($BASETIME). Thus, if the
      file changed after the script, you would get a negative time. Note that most time
      values (86,399 out of 86,400, on average) are fractional, so testing for equality
      with an integer without using the int function is usually futile. Examples:
    
      next unless Esjis::M($file) > 0.5;     # files are older than 12 hours
      &newfile if Esjis::M($file) < 0;       # file is newer than process
      &mailwarning if int(Esjis::A_) == 90;  # file ($_) was accessed 90 days ago today
    
      Available in MSWin32, MacOS, and UNIX-like systems
      ------------------------------------------------------------------------------
      Subroutine and Prototype   Meaning
      ------------------------------------------------------------------------------
      Esjis::M(*), Esjis::M_()   Modification age (measured in days)
      Esjis::A(*), Esjis::A_()   Access age (measured in days)
                                 Same as Esjis::M(*), Esjis::M_() on MacOS
      Esjis::C(*), Esjis::C_()   Inode-modification age (measured in days)
      ------------------------------------------------------------------------------
    
      The Esjis::s, and Esjis::s_ returns file size in bytes if succesful, or undef
      unless successful.
    
      Available in MSWin32, MacOS, and UNIX-like systems
      ------------------------------------------------------------------------------
      Subroutine and Prototype   Meaning
      ------------------------------------------------------------------------------
      Esjis::s(*), Esjis::s_()   File or directory exists and has nonzero size
                                 (the value is the size in bytes)
      ------------------------------------------------------------------------------

    #endif =item * Filename expansion (globbing)

      @glob = Esjis::glob($string);
      @glob = Esjis::glob_;
    
      This subroutine returns the value of $string with filename expansions the way a
      DOS-like shell would expand them, returning the next successive name on each
      call. If $string is omitted, $_ is globbed instead. This is the internal
      subroutine implementing the <*> and glob operator.
      This subroutine function when the pathname ends with chr(0x5C) on MSWin32.
    
      For ease of use, the algorithm matches the DOS-like shell's style of expansion,
      not the UNIX-like shell's. An asterisk ("*") matches any sequence of any
      character (including none). A question mark ("?") matches any one character or
      none. A tilde ("~") expands to a home directory, as in "~/.*rc" for all the
      current user's "rc" files, or "~jane/Mail/*" for all of Jane's mail files.
    
      Note that all path components are case-insensitive, and that backslashes and
      forward slashes are both accepted, and preserved. You may have to double the
      backslashes if you are putting them in literally, due to double-quotish parsing
      of the pattern by perl.
    
      The Esjis::glob subroutine grandfathers the use of whitespace to separate multiple
      patterns such as <*.c *.h>. If you want to glob filenames that might contain
      whitespace, you'll have to use extra quotes around the spacy filename to protect
      it. For example, to glob filenames that have an "e" followed by a space followed
      by an "f", use either of:
    
      @spacies = <"*e f*">;
      @spacies = Esjis::glob('"*e f*"');
      @spacies = Esjis::glob(q("*e f*"));
    
      If you had to get a variable through, you could do this:
    
      @spacies = Esjis::glob("'*${var}e f*'");
      @spacies = Esjis::glob(qq("*${var}e f*"));
    
      Another way on MSWin32
    
      # relative path
      @relpath_file = split(/\n/,`dir /b wildcard\\here*.txt 2>NUL`);
    
      # absolute path
      @abspath_file = split(/\n/,`dir /s /b wildcard\\here*.txt 2>NUL`);
    
      # on COMMAND.COM
      @relpath_file = split(/\n/,`dir /b wildcard\\here*.txt`);
      @abspath_file = split(/\n/,`dir /s /b wildcard\\here*.txt`);

    #if ESCAPE_SECOND_OCTET =item * Statistics about link

      @lstat = Esjis::lstat($file);
      @lstat = Esjis::lstat_;
    
      Like Esjis::stat, returns information on file, except that if file is a symbolic
      link, Esjis::lstat returns information about the link; Esjis::stat returns
      information about the file pointed to by the link. If symbolic links are
      unimplemented on your system, a normal Esjis::stat is done instead. If file is
      omitted, returns information on file given in $_. Returns values (especially
      device and inode) may be bogus.
      This subroutine function when the filename ends with chr(0x5C) on MSWin32.
  • Open directory handle

      $rc = Esjis::opendir(DIR,$dir);
    
      This subroutine opens a directory named $dir for processing by readdir, telldir,
      seekdir, rewinddir, and closedir. The subroutine returns true if successful.
      Directory handles have their own namespace from filehandles.
      This subroutine function when the directory name ends with chr(0x5C) on MSWin32.
  • Statistics about file

      $stat = Esjis::stat(FILEHANDLE);
      $stat = Esjis::stat(DIRHANDLE);
      $stat = Esjis::stat($expr);
      $stat = Esjis::stat_;
      @stat = Esjis::stat(FILEHANDLE);
      @stat = Esjis::stat(DIRHANDLE);
      @stat = Esjis::stat($expr);
      @stat = Esjis::stat_;
    
      In scalar context, this subroutine returns a Boolean value that indicates whether
      the call succeeded. In list context, it returns a 13-element list giving the
      statistics for a file, either the file opened via FILEHANDLE or DIRHANDLE, or
      named by $expr. It's typically used as followes:
    
      ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
          $atime,$mtime,$ctime,$blksize,$blocks) = Esjis::stat($expr);
    
      Not all fields are supported on all filesystem types; unsupported fields return
      0. Here are the meanings of the fields:
    
      -------------------------------------------------------------------------
      Index  Field      Meaning
      -------------------------------------------------------------------------
        0    $dev       Device number of filesystem
                        drive number for MSWin32
                        vRefnum for MacOS
        1    $ino       Inode number
                        zero for MSWin32
                        fileID/dirID for MacOS
        2    $mode      File mode (type and permissions)
        3    $nlink     Nunmer of (hard) links to the file
                        usually one for MSWin32 --- NTFS filesystems may
                        have a value greater than one
                        1 for MacOS
        4    $uid       Numeric user ID of file's owner
                        zero for MSWin32
                        zero for MacOS
        5    $gid       Numeric group ID of file's owner
                        zero for MSWin32
                        zero for MacOS
        6    $rdev      The device identifier (special files only)
                        drive number for MSWin32
                        NULL for MacOS
        7    $size      Total size of file, in bytes
        8    $atime     Last access time since the epoch
                        same as $mtime for MacOS
        9    $mtime     Last modification time since the epoch
                        since 1904-01-01 00:00:00 for MacOS
       10    $ctime     Inode change time (not creation time!) since the epoch
                        creation time instead of inode change time for MSWin32
                        since 1904-01-01 00:00:00 for MacOS
       11    $blksize   Preferred blocksize for file system I/O
                        zero for MSWin32
       12    $blocks    Actual number of blocks allocated
                        zero for MSWin32
                        int(($size + $blksize-1) / $blksize) for MacOS
      -------------------------------------------------------------------------
    
      $dev and $ino, token together, uniquely identify a file on the same system.
      The $blksize and $blocks are likely defined only on BSD-derived filesystems.
      The $blocks field (if defined) is reported in 512-byte blocks. The value of
      $blocks * 512 can differ greatly from $size for files containing unallocated
      blocks, or "hole", which aren't counted in $blocks.
    
      If Esjis::stat is passed the special filehandle consisting of an underline, no
      actual stat(2) is done, but the current contents of the stat structure from
      the last Esjis::stat, Esjis::lstat, or Esjis::stat-based file test subroutine
      (such as Esjis::r, Esjis::w, and Esjis::x) are returned.
    
      Because the mode contains both the file type and its permissions, you should
      mask off the file type portion and printf or sprintf using a "%o" if you want
      to see the real permissions:
    
      $mode = (Esjis::stat($expr))[2];
      printf "Permissions are %04o\n", $mode & 07777;
    
      If $expr is omitted, returns information on file given in $_.
      This subroutine function when the filename ends with chr(0x5C) on MSWin32.
  • Deletes a list of files.

      $unlink = Esjis::unlink(@list);
      $unlink = Esjis::unlink($file);
      $unlink = Esjis::unlink;
    
      Delete a list of files. (Under Unix, it will remove a link to a file, but the
      file may still exist if another link references it.) If list is omitted, it
      unlinks the file given in $_. The subroutine returns the number of files
      successfully deleted.
      This subroutine function when the filename ends with chr(0x5C) on MSWin32.
  • Changes the working directory.

      $chdir = Esjis::chdir($dirname);
      $chdir = Esjis::chdir;
    
      This subroutine changes the current process's working directory to $dirname, if
      possible. If $dirname is omitted, $ENV{'HOME'} is used if set, and $ENV{'LOGDIR'}
      otherwise; these are usually the process's home directory. The subroutine returns
      true on success, false otherwise (and puts the error code into $!).
    
      chdir("$prefix/lib") || die "Can't cd to $prefix/lib: $!";
    
      This subroutine has limitation on the MSWin32. See also BUGS AND LIMITATIONS.
  • Do file

      $return = Esjis::do($file);
    
      The do FILE form uses the value of FILE as a filename and executes the contents
      of the file as a Perl script. Its primary use is (or rather was) to include
      subroutines from a Perl subroutine library, so that:
    
      Esjis::do('stat.pl');
    
      is rather like: 
    
      scalar CORE::eval `cat stat.pl`;   # `type stat.pl` on Windows
    
      except that Esjis::do is more efficient, more concise, keeps track of the current
      filename for error messages, searches all the directories listed in the @INC
      array, and updates %INC if the file is found.
      It also differs in that code evaluated with Esjis::do FILE can not see lexicals in
      the enclosing scope, whereas code in CORE::eval FILE does. It's the same, however,
      in that it reparses the file every time you call it -- so you might not want to do
      this inside a loop unless the filename itself changes at each loop iteration.
    
      If Esjis::do can't read the file, it returns undef and sets $! to the error. If 
      Esjis::do can read the file but can't compile it, it returns undef and sets an
      error message in $@. If the file is successfully compiled, do returns the value of
      the last expression evaluated.
    
      Inclusion of library modules (which have a mandatory .pm suffix) is better done
      with the use and require operators, which also Esjis::do error checking and raise
      an exception if there's a problem. They also offer other benefits: they avoid
      duplicate loading, help with object-oriented programming, and provide hints to the
      compiler on function prototypes.
    
      But Esjis::do FILE is still useful for such things as reading program configuration
      files. Manual error checking can be done this way:
    
      # read in config files: system first, then user
      for $file ("/usr/share/proggie/defaults.rc", "$ENV{HOME}/.someprogrc") {
          unless ($return = Esjis::do($file)) {
              warn "couldn't parse $file: $@" if $@;
              warn "couldn't Esjis::do($file): $!" unless defined $return;
              warn "couldn't run $file"            unless $return;
          }
      }
    
      A long-running daemon could periodically examine the timestamp on its configuration
      file, and if the file has changed since it was last read in, the daemon could use
      Esjis::do to reload that file. This is more tidily accomplished with Esjis::do than
      with Esjis::require.
  • Require file

      Esjis::require($file);
      Esjis::require();
    
      This subroutine asserts a dependency of some kind on its argument. If an argument is
      not supplied, $_ is used.
    
      Esjis::require loads and executes the Perl code found in the separate file whose
      name is given by the $file. This is similar to using a Esjis::do on a file, except
      that Esjis::require checks to see whether the library file has been loaded already
      and raises an exception if any difficulties are encountered. (It can thus be used
      to express file dependencies without worrying about duplicate compilation.) Like
      its cousins Esjis::do, Esjis::require knows how to search the include path stored
      in the @INC array and to update %INC on success.
    
      The file must return true as the last value to indicate successful execution of any
      initialization code, so it's customary to end such a file with 1 unless you're sure
      it'll return true otherwise.
  • Current position of the readdir

      $telldir = Esjis::telldir(DIRHANDLE);
    
      This subroutine returns the current position of the readdir routines on DIRHANDLE.
      This value may be given to seekdir to access a particular location in a directory.
      The subroutine has the same caveats about possible directory compaction as the
      corresponding system library routine. This subroutine might not be implemented
      everywhere that readdir is. Even if it is, no calculation may be done with the
      return value. It's just an opaque value, meaningful only to seekdir.

    #endif /* #if ESCAPE_SECOND_OCTET */ =back

dummy =back to avoid Test::Pod error

NAME

Char - Multibyte Character Support by Traditional Scripting

SYNOPSIS

  # encoding: sjis
  use Char;
  use Char ver.sion;             --- requires minimum version
  use Char ver.sion.0;           --- expects version (match or die)

  subroutines:
    Char::eval(...);
    Char::length(...);
    Char::substr(...);
    Char::ord(...);
    Char::reverse(...);
    Char::getc(...);
    Char::index(...);
    Char::rindex(...);

  # "no Char;" not supported

  supported encodings:
    Arabic, Big5HKSCS, Big5Plus, Cyrillic, EUCJP, EUCTW, GB18030, GBK, Greek,
    HP15, Hebrew, INFORMIXV6ALS, JIS8, KOI8R, KOI8U, KPS9566, Latin1, Latin10,
    Latin2, Latin3, Latin4, Latin5, Latin6, Latin7, Latin8, Latin9, OldUTF8,
    Sjis, TIS620, UHC, USASCII, UTF2, Windows1252, and Windows1258

  supported operating systems:
    Apple Inc. OS X,
    Hewlett-Packard Development Company, L.P. HP-UX,
    International Business Machines Corporation AIX,
    Microsoft Corporation Windows,
    Oracle Corporation Solaris,
    and Other Systems

  supported perl versions:
    perl version 5.005_03 to newest perl

SOFTWARE COMPOSITION

   Char.pm --- Character Oriented Perl by Magic Comment

OTHER SOFTWARE

To using this software, you must get filter software of 'Sjis software family'. See also following 'SEE ALSO'.

INSTALLATION BY MAKE (for UNIX-like system)

To install this software by make, type the following:

   perl Makefile.PL
   make
   make test
   make install

INSTALLATION WITHOUT MAKE (for DOS-like system)

To install this software without make, type the following:

   pmake.bat test
   pmake.bat install    --- install to current using Perl

   pmake.bat dist       --- make distribution package
   pmake.bat ptar.bat   --- make perl script "ptar.bat"

DEPENDENCIES

This software requires perl5.00503 or later.

MAGIC COMMENT

You should show the encoding method of your script by either of the following descriptions. (.+) is an encoding method. It is necessary to describe this description from anywhere of the script.

  m/coding[:=]\s*(.+)/oxms

  Example:

  # -*- coding: Shift_JIS -*-
  print "Emacs like\n";

  # vim:fileencoding=Latin-1
  print "Vim like 1";

  # vim:set fileencoding=GB18030 :
  print "Vim like 2";

  #coding:Modified UTF-8
  print "simple";

ENCODING METHOD

The encoding method is evaluated, after it is regularized.

  regularize:
    1. The upper case characters are converted into lower case.
    2. Left only alphabet and number, others are removed.

The filter software is selected by using the following tables. The script does die if there is no filter software.

  -----------------------------------
  encoding method     filter software
  -----------------------------------
  ascii               USASCII
  usascii             USASCII
  shiftjis            Sjis
  shiftjisx0213       Sjis
  shiftjis2004        Sjis
  sjis                Sjis
  sjisx0213           Sjis
  sjis2004            Sjis
  cp932               Sjis
  windows31j          Sjis
  cswindows31j        Sjis
  sjiswin             Sjis
  macjapanese         Sjis
  macjapan            Sjis
  xsjis               Sjis
  mskanji             Sjis
  csshiftjis          Sjis
  windowscodepage932  Sjis
  ibmcp943            Sjis
  ms932               Sjis
  jisc6220            JIS8
  jisx0201            JIS8
  jis8                JIS8
  ank                 JIS8
  eucjp               EUCJP
  euc                 EUCJP
  ujis                EUCJP
  eucjpms             EUCJP
  eucjpwin            EUCJP
  cp51932             EUCJP
  euctw               EUCTW
  utf8                UTF2
  utf2                UTF2
  utffss              UTF2
  utf8mac             UTF2
  oldutf8             OldUTF8
  cesu8               OldUTF8
  modifiedutf8        OldUTF8
  hp15                HP15
  informixv6als       INFORMIXV6ALS
  gb18030             GB18030
  gbk                 GBK
  gb2312              GBK
  cp936               GBK
  euccn               GBK
  uhc                 UHC
  ksx1001             UHC
  ksc5601             UHC
  ksc56011987         UHC
  ks                  UHC
  cp949               UHC
  windows949          UHC
  kps9566             KPS9566
  kps95662003         KPS9566
  kps95662000         KPS9566
  kps95661997         KPS9566
  kps956697           KPS9566
  euckp               KPS9566
  big5plus            Big5Plus
  big5                Big5Plus
  big5et              Big5Plus
  big5eten            Big5Plus
  tcabig5             Big5Plus
  cp950               Big5Plus
  big5hk              Big5HKSCS
  big5hkscs           Big5HKSCS
  hkbig5              Big5HKSCS
  hkscsbig5           Big5HKSCS
  cp951               Big5HKSCS
  latin1              Latin1
  isoiec88591         Latin1
  iso88591            Latin1
  iec88591            Latin1
  latin2              Latin2
  isoiec88592         Latin2
  iso88592            Latin2
  iec88592            Latin2
  latin3              Latin3
  isoiec88593         Latin3
  iso88593            Latin3
  iec88593            Latin3
  latin4              Latin4
  isoiec88594         Latin4
  iso88594            Latin4
  iec88594            Latin4
  cyrillic            Cyrillic
  isoiec88595         Cyrillic
  iso88595            Cyrillic
  iec88595            Cyrillic
  koi8r               KOI8R
  koi8u               KOI8U
  arabic              Arabic
  isoiec88596         Arabic
  iso88596            Arabic
  iec88596            Arabic
  greek               Greek
  isoiec88597         Greek
  iso88597            Greek
  iec88597            Greek
  hebrew              Hebrew
  isoiec88598         Hebrew
  iso88598            Hebrew
  iec88598            Hebrew
  latin5              Latin5
  isoiec88599         Latin5
  iso88599            Latin5
  iec88599            Latin5
  latin6              Latin6
  isoiec885910        Latin6
  iso885910           Latin6
  iec885910           Latin6
  tis620              TIS620
  tis6202533          TIS620
  isoiec885911        TIS620
  iso885911           TIS620
  iec885911           TIS620
  latin7              Latin7
  isoiec885913        Latin7
  iso885913           Latin7
  iec885913           Latin7
  latin8              Latin8
  isoiec885914        Latin8
  iso885914           Latin8
  iec885914           Latin8
  latin9              Latin9
  isoiec885915        Latin9
  iso885915           Latin9
  iec885915           Latin9
  latin10             Latin10
  isoiec885916        Latin10
  iso885916           Latin10
  iec885916           Latin10
  windows1252         Windows1252
  windows1258         Windows1258
  -----------------------------------

CHARACTER ORIENTED SUBROUTINES

  • Order of Character

      $ord = Char::ord($string);
    
      This subroutine returns the numeric value (ASCII or Multibyte Character) of the
      first character of $string. The return value is always unsigned.
  • Reverse List or String

      @reverse = Char::reverse(@list);
      $reverse = Char::reverse(@list);
    
      In list context, this subroutine returns a list value consisting of the elements
      of @list in the opposite order. The subroutine can be used to create descending
      sequences:
    
      for (Char::reverse(1 .. 10)) { ... }
    
      Because of the way hashes flatten into lists when passed as a @list, reverse can
      also be used to invert a hash, presuming the values are unique:
    
      %barfoo = Char::reverse(%foobar);
    
      In scalar context, the subroutine concatenates all the elements of LIST and then
      returns the reverse of that resulting string, character by character.
  • Returns Next Character

      $getc = Char::getc(FILEHANDLE);
      $getc = Char::getc($filehandle);
      $getc = Char::getc;
    
      This subroutine returns the next character from the input file attached to
      FILEHANDLE. It returns undef at end-of-file, or if an I/O error was encountered.
      If FILEHANDLE is omitted, the subroutine reads from STDIN.
    
      This subroutine is somewhat slow, but it's occasionally useful for single-character
      input from the keyboard -- provided you manage to get your keyboard input
      unbuffered. This subroutine requests unbuffered input from the standard I/O library.
      Unfortunately, the standard I/O library is not so standard as to provide a portable
      way to tell the underlying operating system to supply unbuffered keyboard input to
      the standard I/O system. To do that, you have to be slightly more clever, and in
      an operating-system-dependent fashion. Under Unix you might say this:
    
      if ($BSD_STYLE) {
          system "stty cbreak </dev/tty >/dev/tty 2>&1";
      }
      else {
          system "stty", "-icanon", "eol", "\001";
      }
    
      $key = Char::getc;
    
      if ($BSD_STYLE) {
          system "stty -cbreak </dev/tty >/dev/tty 2>&1";
      }
      else {
          system "stty", "icanon", "eol", "^@"; # ASCII NUL
      }
      print "\n";
    
      This code puts the next character typed on the terminal in the string $key. If your
      stty program has options like cbreak, you'll need to use the code where $BSD_STYLE
      is true. Otherwise, you'll need to use the code where it is false.
  • Length by Character

      $length = Char::length($string);
      $length = Char::length();
    
      This subroutine returns the length in characters of the scalar value $string. If
      $string is omitted, it returns the Char::length of $_.
    
      Do not try to use length to find the size of an array or hash. Use scalar @array
      for the size of an array, and scalar keys %hash for the number of key/value pairs
      in a hash. (The scalar is typically omitted when redundant.)
    
      To find the length of a string in bytes rather than characters, say:
    
      $blen = length($string);
    
      or
    
      $blen = CORE::length($string);
  • Substr by Character

      $substr = Char::substr($string,$offset,$length,$replacement);
      $substr = Char::substr($string,$offset,$length);
      $substr = Char::substr($string,$offset);
    
      This subroutine extracts a substring out of the string given by $string and
      returns it. The substring is extracted starting at $offset characters from the
      front of the string.
      If $offset is negative, the substring starts that far from the end of the string
      instead. If $length is omitted, everything to the end of the string is returned.
      If $length is negative, the length is calculated to leave that many characters off
      the end of the string. Otherwise, $length indicates the length of the substring to
      extract, which is sort of what you'd expect.
    
      An alternative to using Char::substr as an lvalue is to specify the $replacement
      string as the fourth argument. This allows you to replace parts of the $string and
      return what was there before in one operation, just as you can with splice. The next
      example also replaces the last character of $var with "Curly" and puts that replaced
      character into $oldstr: 
    
      $oldstr = Char::substr($var, -1, 1, "Curly");
    
      If you assign something shorter than the length of your substring, the string will
      shrink, and if you assign something longer than the length, the string will grow to
      accommodate it. To keep the string the same length, you may need to pad or chop your
      value using sprintf or the x operator. If you attempt to assign to an unallocated
      area past the end of the string, Char::substr raises an exception.
    
      To prepend the string "Larry" to the current value of $_, use:
    
      Char::substr($var, 0, 0, "Larry");
    
      To instead replace the first character of $_ with "Moe", use:
    
      Char::substr($var, 0, 1, "Moe");
    
      And finally, to replace the last character of $var with "Curly", use:
    
      Char::substr($var, -1, 1, "Curly");
  • Index by Character

      $index = Char::index($string,$substring,$offset);
      $index = Char::index($string,$substring);
    
      This subroutine searches for one string within another. It returns the position of
      the first occurrence of $substring in $string. The $offset, if specified, says how
      many characters from the start to skip before beginning to look. Positions are
      based at 0. If the substring is not found, the subroutine returns one less than
      the base, ordinarily -1. To work your way through a string, you might say:
    
      $pos = -1;
      while (($pos = Char::index($string, $lookfor, $pos)) > -1) {
          print "Found at $pos\n";
          $pos++;
      }
    
      Three Indexes
      -------------------------------------------------------------------------
      Function       Works as    Returns as   Description
      -------------------------------------------------------------------------
      index          Character   Byte         JPerl semantics (most useful)
      Char::index    Character   Character    Character-oriented semantics
      CORE::index    Byte        Byte         Byte-oriented semantics
      -------------------------------------------------------------------------
  • Rindex by Character

      $rindex = Char::rindex($string,$substring,$position);
      $rindex = Char::rindex($string,$substring);
    
      This subroutine works just like Char::index except that it returns the position
      of the last occurrence of $substring in $string (a reverse index). The subroutine
      returns -1 if not $substring is found. $position, if specified, is the rightmost
      position that may be returned. To work your way through a string backward, say:
    
      $pos = Char::length($string);
      while (($pos = Char::rindex($string, $lookfor, $pos)) >= 0) {
          print "Found at $pos\n";
          $pos--;
      }
    
      Three Rindexes
      -------------------------------------------------------------------------
      Function       Works as    Returns as   Description
      -------------------------------------------------------------------------
      rindex         Character   Byte         JPerl semantics (most useful)
      Char::rindex   Character   Character    Character-oriented semantics
      CORE::rindex   Byte        Byte         Byte-oriented semantics
      -------------------------------------------------------------------------
  • Eval by Character

      $eval = Char::eval { block };
      $eval = Char::eval $expr;
      $eval = Char::eval;
    
      The Char::eval keyword serves two distinct but related purposes in JPerl.
      These purposes are represented by two forms of syntax, Char::eval { block }
      and Char::eval $expr. The first form traps runtime exceptions (errors)
      that would otherwise prove fatal, similar to the "try block" construct in
      C++ or Java. The second form compiles and executes little bits of code on
      the fly at runtime, and also (conveniently) traps any exceptions just like
      the first form. But the second form runs much slower than the first form,
      since it must parse the string every time. On the other hand, it is also
      more general. Whichever form you use, Char::eval is the preferred way to do
      all exception handling in JPerl.
    
      For either form of Char::eval, the value returned from an Char::eval is
      the value of the last expression evaluated, just as with subroutines.
      Similarly, you may use the return operator to return a value from the
      middle of the eval. The expression providing the return value is evaluated
      in void, scalar, or list context, depending on the context of the
      Char::eval itself. See wantarray for more on how the evaluation context
      can be determined.
    
      If there is a trappable error (including any produced by the die operator),
      Char::eval returns undef and puts the error message (or object) in $@. If
      there is no error, $@ is guaranteed to be set to the null string, so you
      can test it reliably afterward for errors. A simple Boolean test suffices:
    
          Char::eval { ... }; # trap runtime errors
          if ($@) { ... }     # handle error
    
      (Prior to Perl 5.16, a bug caused undef to be returned in list context for
      syntax errors, but not for runtime errors.)
    
      The Char::eval { block } form is syntax checked and compiled at compile time,
      so it is just as efficient at runtime as any other block. (People familiar
      with the slow Char::eval $expr form are occasionally confused on this issue.)
      Because the { block } is compiled when the surrounding code is, this form of
      Char::eval cannot trap syntax errors.
    
      The Char::eval $expr form can trap syntax errors because it parses the code
      at runtime. (If the parse is unsuccessful, it places the parse error in $@,
      as usual.) If $expr is omitted, evaluates $_ .
    
      Otherwise, it executes the value of $expr as though it were a little JPerl
      script. The code is executed in the context of the current of the current
      JPerl script, which means that it can see any enclosing lexicals from a
      surrounding scope, and that any nonlocal variable settings remain in effect
      after the Char::eval is complete, as do any subroutine or format definitions.
      The code of the Char::eval is treated as a block, so any locally scoped
      variables declared within the Char::eval last only until the Char::eval is
      done. (See my and local.) As with any code in a block, a final semicolon is
      not required.
    
      Char::eval will be escaped as follows:
    
      -------------------------------------------------
      Before                  After
      -------------------------------------------------
      Char::eval { block }    eval { block }
      Char::eval $expr        eval Char::escape $expr
      Char::eval              eval Char::escape
      -------------------------------------------------
    
      To tell the truth, the subroutine Char::eval does not exist. If it exists,
      you will troubled, when Char::eval has a parameter that is single quoted
      string included my variables. Char::escape is a subroutine that makes Perl
      script from JPerl script.
    
      Here is a simple JPerl shell. It prompts the user to enter a string of
      arbitrary JPerl code, compiles and executes that string, and prints whatever
      error occurred:
    
          #!/usr/bin/perl
          # jperlshell.pl - simple JPerl shell
          use Char;
          print "\nEnter some JPerl code: ";
          while (<STDIN>) {
              Char::eval;
              print $@;
              print "\nEnter some more JPerl code: ";
          }
    
      Here is a rename.pl script to do a mass renaming of files using a JPerl
      expression:
    
          #!/usr/bin/perl
          # rename.pl - change filenames
          use Char;
          $op = shift;
          for (@ARGV) {
              $was = $_;
              Char::eval $op;
              die if $@;
              # next line calls the built-in function, not
              # the script by the same name
              if ($was ne $_) {
                  print STDERR "rename $was --> $_\n";
                  rename($was,$_);
              }
          }
    
      You'd use that script like this:
    
          C:\WINDOWS> perl rename.pl 's/\.orig$//' *.orig
          C:\WINDOWS> perl rename.pl 'y/A-Z/a-z/ unless /^Make/' *
          C:\WINDOWS> perl rename.pl '$_ .= ".bad"' *.f
    
      Since Char::eval traps errors that would otherwise prove fatal, it is useful
      for determining whether particular features (such as fork or symlink) are
      implemented.
    
      Because Char::eval { block } is syntax checked at compile time, any syntax
      error is reported earlier. Therefore, if your code is invariant and both
      Char::eval $expr and Char::eval { block } will suit your purposes equally
      well, the { block } form is preferred. For example:
    
          # make divide-by-zero nonfatal
          Char::eval { $answer = $a / $b; };
          warn $@ if $@;
    
          # same thing, but less efficient if run multiple times
          Char::eval '$answer = $a / $b';
          warn $@ if $@;
    
          # a compile-time syntax error (not trapped)
          Char::eval { $answer = }; # WRONG
    
          # a runtime syntax error
          Char::eval '$answer =';   # sets $@
    
      Here, the code in the { block } has to be valid JPerl code to make it past
      the compile phase. The code in the $expr doesn't get examined until runtime,
      so it doesn't cause an error until runtime.
    
      Using the Char::eval { block } form as an exception trap in libraries does
      have some issues. Due to the current arguably broken state of __DIE__ hooks,
      you may wish not to trigger any __DIE__ hooks that user code may have
      installed. You can use the local $SIG{__DIE__} construct for this purpose,
      as this example shows:
    
          # a private exception trap for divide-by-zero
          Char::eval { local $SIG{'__DIE__'}; $answer = $a / $b; };
          warn $@ if $@;
    
      This is especially significant, given that __DIE__ hooks can call die again,
      which has the effect of changing their error messages:
    
          # __DIE__ hooks may modify error messages
          {
              local $SIG{'__DIE__'} =
                  sub { (my $x = $_[0]) =~ s/foo/bar/g; die $x };
              Char::eval { die "foo lives here" };
              print $@ if $@;                # prints "bar lives here"
          }
    
      Because this promotes action at a distance, this counterintuitive behavior
      may be fixed in a future release.
    
      With an Char::eval, you should be especially careful to remember what's being
      looked at when:
    
          Char::eval $x;        # CASE 1
          Char::eval "$x";      # CASE 2
    
          Char::eval '$x';      # CASE 3
          Char::eval { $x };    # CASE 4
    
          Char::eval "\$$x++";  # CASE 5
          $$x++;                # CASE 6
    
      CASEs 1 and 2 above behave identically: they run the code contained in the
      variable $x. (Although CASE 2 has misleading double quotes making the reader
      wonder what else might be happening (nothing is).) CASEs 3 and 4 likewise
      behave in the same way: they run the code '$x' , which does nothing but return
      the value of $x. (CASE 4 is preferred for purely visual reasons, but it also
      has the advantage of compiling at compile-time instead of at run-time.) CASE 5
      is a place where normally you would like to use double quotes, except that in
      this particular situation, you can just use symbolic references instead, as
      in CASE 6.
    
      Before Perl 5.14, the assignment to $@ occurred before restoration of
      localized variables, which means that for your code to run on older versions,
      a temporary is required if you want to mask some but not all errors:
    
          # alter $@ on nefarious repugnancy only
          {
              my $e;
              {
                  local $@; # protect existing $@
                  Char::eval { test_repugnancy() };
                  # $@ =~ /nefarious/ and die $@; # Perl 5.14 and higher only
                  $@ =~ /nefarious/ and $e = $@;
              }
              die $e if defined $e
          }
    
      The block of Char::eval { block } does not count as a loop, so the loop
      control statements next, last, or redo cannot be used to leave or restart the
      block.
  • Filename Globbing

      @glob = glob($expr);
      $glob = glob($expr);
      @glob = glob;
      $glob = glob;
      @glob = <*>;
      $glob = <*>;
    
      Performs filename expansion (globbing) on $expr, returning the next successive
      name on each call. If $expr is omitted, $_ is globbed instead.

AUTHOR

INABA Hitoshi <ina@cpan.org>

This project was originated by INABA Hitoshi.

LICENSE AND COPYRIGHT

This software is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

SEE ALSO

 Other Tools
 http://search.cpan.org/dist/jacode/

 BackPAN
 http://backpan.perl.org/authors/id/I/IN/INA/

ACKNOWLEDGEMENTS

This software was made referring to software and the document that the following hackers or persons had made. Especially, Yukihiro Matsumoto taught to us,

CSI is not impossible.

I am thankful to all persons.

 Larry Wall, Perl
 http://www.perl.org/

 Yukihiro "Matz" Matsumoto, YAPC::Asia2006 Ruby on Perl(s)
 http://www.rubyist.net/~matz/slides/yapc2006/

 About Ruby M17N in Rubyist Magazine
 http://jp.rubyist.net/magazine/?0025-Ruby19_m17n#l13