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

NAME

Convert::ASCIInames - ASCII names for control characters

SYNOPSIS

 use Convert::ASCIInames;

 Convert::ASCIInames::Configure(fallthrough => 1);
 $name = ASCIIname($character_ordinal);
 $name = ASCIIaltname($character_ordinal);
 $name = ASCIIdescription($character_ordinal);
 $name = ASCIIaltdescription($character_ordinal);
 $character_ordinal = ASCIIordinal($name);

DESCRIPTION

Most if not all of the non-printing characters of the ASCII character set had special significance in the days of teletypes and paper tapes. For example, the character code 0x00 would be sent repeatedly in order to give the receiving end a chance to catch up; it signified "no action" and so was named NUL. The sending end might follow each line of text with a number of NUL bytes in order to give the receiving end a chance to return its print carriage to the left margin. The control characters (so-called because they were used to control aspects of communication or receiving devices) were given short 2-to-4 letter names, like CR, EOT, ACK, and NAK.

Some of these special purposes have become obsolete, but some of them are still in use. For example, character 0x07 (BEL) is used to ring the feeper; 0x05 (ENQ) is recognised by many terminals as a trigger to report their status; and 0x08 (BS) still means "move the cursor back one space".

This module will return the ASCII name for specified characters, or the character code if given an ASCII name. In addition, the full descriptive name ("Start of Heading" instead of SOH) is available, although reverse translation of the descriptions isn't provided.

Some control characters have altername names. Character 0x13 is named DC3 ("Device Control 3"), but is probably better known by its alternate name of XOFF. These alternate names are also available through this module's functions.

USAGE

Each of the functions in this module is described below. They are listed in lexical order, rather than functional.

If you request the name (or alternate name) of a character that doesn't have one, you'll either get the actual character itself, or the name (if it has one) from the other list. For instance, if you request the alternate name for 0x00, which doesn't have one, the return value will either be NUL (the primary name) or the value of chr(0x00). The former is called "falling through," and is controlled by the setting of the fallthrough configuration option. If the option is set to a true value, the module will attempt to give you the best name it can; if it's set to a false value, you'll either get exactly what you requested (such as the alternate name) or the character itself.

If you provide an invalid character ordinal (such as a non-integer, or one outside the range of 0-255), Convert::ASCIInames will throw a message using carp() and use a standard substitute value instead:

o Ordinal is omitted or is a zero-length string

The value 0x00 will be used.

o Ordinal < 0 or > 255

The value 255 (0xff) will be used instead.

o Ordinal is a non-integer

The ordinal of the first character of the argument will be used. If option strict_ordinals is set, a warning message will be issued.

ASCIIaltdescription

 $text = ASCIIaltdescription($ordinal);

This function returns the description for the alternate name, if any, for the character with the specified ordinal. If there is no altername name, the description of the primary name (if any) will be returned if the fallthrough option is set; otherwise the value of chr($ordinal) will be returned.

ASCIIaltname

 $text = ASCIIaltname($ordinal);

This function returns the alternate name, if any, for the character with the specified ordinal. If there is no altername name, the primary name (if any) will be returned if the fallthrough option is set; otherwise the value of chr($ordinal) will be returned.

ASCIIdescription

 $text = ASCIIdescription($ordinal);

This function returns the description for the primary name, if any, for the character with the specified ordinal. If there is no primary name, the description of the alternate name (if any) will be returned if the fallthrough option is set; otherwise the value of chr($ordinal) will be returned.

Note that it is unlikely that a character will have an alternate name but not a primary one.

ASCIIname

This function returns the primary name, if any, for the character with the specified ordinal. If there is no primary name, the alternate name (if any) will be returned if the fallthrough option is set; otherwise the value of chr($ordinal) will be returned.

Note that it is unlikely that a character will have an alternate name but not a primary one.

ASCIIordinal

 $ordinal = ASCIIordinal($name)

This function will attempt to look up the specified name in the primary and alternate lists, and return the ordinal of any match it finds. For example:

  my $ord = ASCIIordinal('xoff');
  printf("xoff = 0x%02x\n", $ord);

would print

  xoff = 0x13

If the name does not appear in the primary or alternate list, the ordinal of the first character of the string will be returned.

The argument is not case-sensitive.

Convert::ASCIInames::Configure

 Convert::ASCIInames::Configure(..options..)

This function sets the options controlling some details of Convert::ASCIInames' operation. Options are specifed as either a hash or a hashref:

 Convert::ASCIInames::Configure(fallback => 1);

 my $opts = { fallback => 1, strict_ordinals => 0};
 Convert::ASCIInames::Configure($opts);

The possible options are:

o fallthrough

If this option is set to a true value, Convert::ASCIInames will search both the primary and the alternate (or vice versa) lists for the specified character or name. If set to a false value, only the list you indicate will be searched.

Default is true.

o strict_ordinals

When a function that takes a character ordinal is passed an argument that is nominally invalid (i.e., not a positive integer between 0 and 255 inclusive), it will use the ord() value of the first byte of the argument. If the strict_ordinals option is set to true, a warning message will be generated, just in case this isn't what you intended. If set to false, there is no message.

The default value is false.

BUGS

None known.

SUPPORT

The cpan-modules@Sourcery.Org mailing list; send a message containing only the word subscribe to cpan-modules-request@Sourcery.Org to join the list.

AUTHOR

 Ken Coar
 CPAN ID: ROUS
 Ken.Coar@Golux.Com
 http://Ken.Coar.Org/

COPYRIGHT

This program is free software licensed under the...

    Apache Software License (Version 2.0)

The full text of the license can be found in the LICENCE file included with this module.

SEE ALSO

perl(1), and charnames(3pm) (function viacode in Perl 5.8.1 and later).

1 POD Error

The following errors were encountered while parsing the POD:

Around line 481:

=end text without matching =begin. (Stack: [empty])