Big5
view release on metacpan or search on metacpan
lib/Big5.pm view on Meta::CPAN
$ord = Big5::ord($string);
This subroutine returns the numeric value (ASCII or Big5 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 Big5 qw(ord);", ord of your script will be rewritten in
Big5::ord. Big5::ord is not compatible with ord of JPerl.
=item * Reverse List or String
@reverse = Big5::reverse(@list);
$reverse = Big5::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 Big5 qw(reverse);", reverse of your script will be
rewritten in Big5::reverse. Big5::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
=item * Returns Next Character
$getc = Big5::getc(FILEHANDLE);
$getc = Big5::getc($filehandle);
$getc = Big5::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 = Big5::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 Big5 qw(getc);", getc of your script will be rewritten
in Big5::getc. Big5::getc is not compatible with getc of JPerl.
=item * Length by Big5 Character
$length = Big5::length($string);
$length = Big5::length();
This subroutine returns the length in characters (programmer-visible characters)
of the scalar value $string. If $string is omitted, it returns the Big5::length
of $_.
Do not try to use Big5::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
=item * Substr by Big5 Character
$substr = Big5::substr($string,$offset,$length,$replacement);
$substr = Big5::substr($string,$offset,$length);
$substr = Big5::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 = Big5::substr $s, 4, 5; # black
my $middle = Big5::substr $s, 4, -11; # black cat climbed the
my $end = Big5::substr $s, 14; # climbed the green tree
my $tail = Big5::substr $s, -4; # tree
my $z = Big5::substr $s, -4, 2; # tr
lib/Big5.pm view on Meta::CPAN
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.
=item * Ordinal Value of Byte
$ord = CORE::ord($expr);
This function returns the numeric value of the first byte of $expr, regardless
of "use Big5 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.
=item * 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 Big5 qw(reverse);" exists or not.
=item * 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.
=item * 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++;
}
=item * 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--;
}
=back
=head1 Yada Yada Operator (Big5 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 { ... }
...;
( run in 1.166 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )