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

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::capture(...);
    Esjis::ignorecase(...);
    Esjis::chr(...);
    Esjis::chr_;
    Esjis::X ...;
    Esjis::X_;
    Esjis::glob(...);
    Esjis::glob_;
    Esjis::lstat(...);
    Esjis::lstat_;
    Esjis::opendir(...);
    Esjis::stat(...);
    Esjis::stat_;
    Esjis::unlink(...);
    Esjis::chdir(...);
    Esjis::do(...);
    Esjis::require(...);
    Esjis::telldir(...);

  # "no Esjis;" not supported

ABSTRACT

This module is a run-time routines of the Sjis module. Because the Sjis module automatically uses this module, you need not use directly.

BUGS AND LIMITATIONS

Please patches and report problems to author are welcome.

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;

  Scans a ShiftJIS $string for delimiters that match pattern and splits the ShiftJIS
  $string into a list of substrings, returning the resulting list value in list
  context, or the count of substrings in scalar context. The delimiters are
  determined by repeated pattern matching, using the regular expression given in
  pattern, so the delimiters may be of any size and need not be the same ShiftJIS
  $string on every match. If the pattern doesn't match at all, Esjis::split returns
  the original ShiftJIS $string as a single substring. If it matches once, you get
  two substrings, and so on.
  If $limit is specified and is not negative, the function splits into no more than
  that many fields. If $limit is negative, it is treated as if an arbitrarily large
  $limit has been specified. If $limit is omitted, trailing null fields are stripped
  from the result (which potential users of pop would do well to remember).
  If ShiftJIS $string is omitted, the function splits the $_ ShiftJIS string.
  If $patten is also omitted, the function splits on whitespace, /\s+/, after
  skipping any leading whitespace.
  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.
Transliteration
  $tr = Esjis::tr($variable,$bind_operator,$searchlist,$replacementlist,$modifier);
  $tr = Esjis::tr($variable,$bind_operator,$searchlist,$replacementlist);

  This function 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
  ------------------------------------------------------
Chop string
  $chop = Esjis::chop(@list);
  $chop = Esjis::chop();
  $chop = Esjis::chop;

  Chops off the last character of a ShiftJIS string contained in the variable (or
  ShiftJIS strings in each element of a @list) and returns the character chopped.
  The Esjis::chop operator is used primarily to remove the newline from the end of
  an input record but is more efficient than s/\n$//. If no argument is given, the
  function chops the $_ variable.
Index string
  $pos = Esjis::index($string,$substr,$position);
  $pos = Esjis::index($string,$substr);

  Returns the position of the first occurrence of $substr in ShiftJIS $string.
  The start, if specified, specifies the $position to start looking in the ShiftJIS
  $string. Positions are integer numbers based at 0. If the substring is not found,
  the Esjis::index function returns -1.
Reverse index string
  $pos = Esjis::rindex($string,$substr,$position);
  $pos = Esjis::rindex($string,$substr);

  Works just like Esjis::index except that it returns the position of the last
  occurence of $substr in ShiftJIS $string (a reverse index). The function returns
  -1 if not found. $position, if specified, is the rightmost position that may be
  returned, i.e., how far in the ShiftJIS string the function can search.
Lower case string
  $lc = Esjis::lc($string);
  $lc = Esjis::lc_;

  Returns a lowercase version of ShiftJIS string (or $_, if omitted). This is the
  internal function implementing the \L escape in double-quoted strings.
Lower case first character of string
  $lcfirst = Esjis::lcfirst($string);
  $lcfirst = Esjis::lcfirst_;

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

  Returns an uppercased version of ShiftJIS string (or $_, if string is omitted).
  This is the internal function implementing the \U escape in double-quoted
  strings.
Upper case first character of string
  $ucfirst = Esjis::ucfirst($string);
  $ucfirst = Esjis::ucfirst_;

  Returns a version of ShiftJIS string (or $_, if omitted) with the first character
  uppercased. This is the internal function implementing the \u escape in double-
  quoted strings.
Make capture number
  $capturenumber = Esjis::capture($string);

  This function is internal use to m/ /i, s/ / /i, split and qr/ /i.
Make ignore case string
  @ignorecase = Esjis::ignorecase(@string);

  This function is internal use to m/ /i, s/ / /i, split and qr/ /i.
Make character
  $chr = Esjis::chr($code);
  $chr = Esjis::chr_;

  This function returns the character represented by that $code in the character
  set. For example, Esjis::chr(65) is "A" in either ASCII or ShiftJIS, and
  Esjis::chr(0x82a0) is a ShiftJIS HIRAGANA LETTER A. For the reverse of Esjis::chr,
  use Sjis::ord.
File test operator -X
  A file test operator is an unary operator that tests a pathname or a filehandle.
  If $string is omitted, it uses $_ by function Esjis::r_.
  The following functions function when the pathname ends with chr(0x5C) on MSWin32.

  $test = Esjis::r $string;
  $test = Esjis::r_;

  Returns 1 when true case or '' when false case.
  Returns undef unless successful.

  Function and Prototype     Meaning
  ------------------------------------------------------------------------------
  Esjis::r(*), Esjis::r_()   File is readable by effective uid/gid
  Esjis::w(*), Esjis::w_()   File is writable by effective uid/gid
  Esjis::x(*), Esjis::x_()   File is executable by effective uid/gid
  Esjis::o(*), Esjis::o_()   File is owned by effective uid
  Esjis::R(*), Esjis::R_()   File is readable by real uid/gid
  Esjis::W(*), Esjis::W_()   File is writable by real uid/gid
  Esjis::X(*), Esjis::X_()   File is executable by real uid/gid
  Esjis::O(*), Esjis::O_()   File is owned by real uid
  Esjis::e(*), Esjis::e_()   File exists
  Esjis::z(*), Esjis::z_()   File has zero size
  Esjis::f(*), Esjis::f_()   File is a plain file
  Esjis::d(*), Esjis::d_()   File is a directory
  Esjis::l(*), Esjis::l_()   File is a symbolic link
  Esjis::p(*), Esjis::p_()   File is a named pipe (FIFO)
  Esjis::S(*), Esjis::S_()   File is a socket
  Esjis::b(*), Esjis::b_()   File is a block special file
  Esjis::c(*), Esjis::c_()   File is a character special file
  Esjis::t(*), Esjis::t_()   Filehandle is opened to a tty
  Esjis::u(*), Esjis::u_()   File has setuid bit set
  Esjis::g(*), Esjis::g_()   File has setgid bit set
  Esjis::k(*), Esjis::k_()   File has sticky bit set
  ------------------------------------------------------------------------------

  Returns 1 when true case or '' when false case.
  Returns undef unless successful.

  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 deosn't work when given the special
  filehandle consisting of a solitary underline.

  Function and Prototype     Meaning
  ------------------------------------------------------------------------------
  Esjis::T(*), Esjis::T_()   File is a text file
  Esjis::B(*), Esjis::B_()   File is a binary file (opposite of -T)
  ------------------------------------------------------------------------------

  Returns useful value if successful, or undef unless successful.

  $value = Esjis::s $string;
  $value = Esjis::s_;

  Function and Prototype     Meaning
  ------------------------------------------------------------------------------
  Esjis::s(*), Esjis::s_()   File has nonzero size (returns size)
  Esjis::M(*), Esjis::M_()   Age of file (at startup) in days since modification
  Esjis::A(*), Esjis::A_()   Age of file (at startup) in days since last access
  Esjis::C(*), Esjis::C_()   Age of file (at startup) in days since inode change
  ------------------------------------------------------------------------------
Filename expansion (globbing)
  @glob = Esjis::glob($string);
  @glob = Esjis::glob_;

  Performs filename expansion (DOS-like globbing) on $string, returning the next
  successive name on each call. If $string is omitted, $_ is globbed instead.
  This function function when the pathname ends with chr(0x5C) on MSWin32.

  For example, C<<..\\l*b\\file/*glob.p?>> will work as expected (in that it will
  find something like '..\lib\File/DosGlob.pm' alright). 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.
  A tilde ("~") expands to the current user's home directory.

  Spaces in the argument delimit distinct patterns, so C<glob('*.exe *.dll')> globs
  all filenames that end in C<.exe> or C<.dll>. If you want to put in literal spaces
  in the glob pattern, you can escape them with either double quotes.
  e.g. C<glob('c:/"Program Files"/*/*.dll')>.
  @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 $_.
  This function function when the filename ends with chr(0x5C) on MSWin32.
Open directory handle
  $rc = Esjis::opendir(DIR,$dir);

  Opens a directory for processing by readdir, telldir, seekdir, rewinddir and
  closedir. The function returns true if successful.
  This function function when the directory name ends with chr(0x5C) on MSWin32.
Statistics about file
  @stat = Esjis::stat($file);
  @stat = Esjis::stat_;

  Returns a 13-element list giving the statistics for a file, indicated by either
  a filehandle or an expression that gives its name. It's typically used as
  follows:

  ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
      $atime,$mtime,$ctime,$blksize,$blocks) = Esjis::stat($file);

  Not all fields are supported on all filesystem types. Here are the meanings of
  the fields:

  Field     Meaning
  -----------------------------------------------------------------
  dev       Device number of filesystem
  ino       Inode number
  mode      File mode (type and permissions)
  nlink     Nunmer of (hard) links to the file
  uid       Numeric user ID of file's owner
  gid       Numeric group ID of file's owner
  rdev      The device identifier (special files only)
  size      Total size of file, in bytes
  atime     Last access time since the epoch
  mtime     Last modification time since the epoch
  ctime     Inode change time (not creation time!) since the epoch
  blksize   Preferred blocksize for file system I/O
  blocks    Actual number of blocks allocated
  -----------------------------------------------------------------

  $dev and $ino, token together, uniquely identify a file. The $blksize and
  $blocks are likely defined only on BSD-derived filesystem. The $blocks field
  (if defined) is reported in 512-byte blocks.
  If stat is passed the special filehandle consisting of an underline, no
  actual stat is done, but the current contents of the stat structure from the
  last stat or stat-based file test (the -x operators) is returned.
  If file is omitted, returns information on file given in $_.
  This function 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 function returns the number of files
  successfully deleted.
  This function function when the filename ends with chr(0x5C) on MSWin32.
Changes the working directory.
  $chdir = Esjis::chdir($dirname);
  $chdir = Esjis::chdir;

  Changes the working directory to $dirname, if possible. If $dirname is omitted,
  it changes to the home directory. The function returns 1 upon success, 0
  otherwise (and puts the error code into $!).

  This function can't function when the $dirname ends with chr(0x5C) on perl5.006,
  perl5.008, perl5.010, perl5.012 on MSWin32.
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 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 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 function asserts a dependency of some kind on its argument. If an argument is not
  supplied, $_ is used.

  If the argument is a string, Esjis::require loads and executes the Perl code found in
  the separate file whose name is given by the string. This is similar to performing 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 and use, Esjis::require knows how
  to search the include path stored in the @INC array and to update %INC upon 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.

  See also do file.
current position of the readdir
  Esjis::telldir(DIRHANDLE);

  This function 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 function has the same caveats about possible directory compaction as the
  corresponding system library routine. This function 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.