Cover V11, I10
oct2002.tar

Listing 2 CSV2db::Mac

package CSV2db::Mac;

use strict;
use vars qw($VERSION @ISA @EXPORT_OK);
use Carp;
require Exporter;

$VERSION = substr q$Revision: 1.0 $, 10;
@ISA = qw(Exporter);
@EXPORT_OK = qw(macroman2iso);

# Translate a string from MacRoman to an approximation of ISO-8859-1.
# This is a pragmatic, not perfect, translation, since some characters
# in MacRoman simply don't exist in ISO-8859-1.
sub macroman2iso {
    # modified from http://bumppo.net/lists/macperl/2000/02/msg00033.html
    # (by Axel Rose <rose@sj.com>)
    my %chars = (
         128, "\304",  # &Auml;
         129, "\305",  # &Aring;
         130, "\307",  # &Ccedil;
         131, "\311",  # &Eacute;
         132, "\321",  # &Ntilde;
         133, "\326",  # &Ouml;
         134, "\334",  # &Uuml;
         135, "\341",  # &aacute;
         136, "\340",  # &agrave;
         137, "\342",  # &acirc;
         138, "\344",  # &auml;
         139, "\343",  # &atilde;
         140, "\345",  # &aring;
         141, "\347",  # &ccedil;
         142, "\351",  # &eacute;
         143, "\350",  # &egrave;
         144, "\352",  # &ecirc;
         145, "\353",  # &euml;
         146, "\355",  # &iacute;
         147, "\354",  # &igrave;
         148, "\356",  # &icirc;
         149, "\357",  # &iuml;
         150, "\361",  # &ntilde;
         151, "\363",  # &oacute;
         152, "\362",  # &ograve;
         153, "\364",  # &ocirc;
         154, "\366",  # &ouml;
         155, "\365",  # &otilde;
         156, "\372",  # &uacute;
         157, "\371",  # &ugrave;
         158, "\373",  # &ucirc;
         159, "\374",  # &uuml;
         160, "*",     # dagger
         161, "\260",  # &deg;
         162, "\242",  # &cent;
         163, "\243",  # &pound;
         164, "\247",  # &sect;
         165, "\267",  # bullet
         166, "\266",  # &para;
         167, "\337",  # &szlig;
         168, "\256",  # &reg;
         169, "\251",  # &copy;
         170, "(TM)",  # trademark
         171, "\264",  # &acute;
         172, "\250",  # &uml;
         173, "<>",    # not_eq
         174, "\306",  # &AElig;
         175, "\330",  # &Oslash;
         176, "infinity",  # infinity
         177, "\261",  # &plusmn;
         178, "<=",    # less/eq
         179, ">=",    # great/eq
         180, "\245",  # &yen;
         181, "\265",  # &micro;
         182, "delta", # delta
         183, "Sigma", # Sigma
         184, "Pi",    # Pi
         185, "pi",    # pi
         186, "integral",  # integral
         187, "\252",  # &ordf;
         188, "\272",  # &ordm;
         189, "Omega", # Omega
         190, "\346",  # &aelig;
         191, "\370",  # &oslash;
         192, "\277",  # &iquest;
         193, "\241",  # &iexcl;
         194, "\254",  # &not;
         195, "sqrt",  # radical
         196, "f",     # florin
         197, "~=",    # apeq
         198, "Delta", # Delta
         199, "\253",  # &laqot;
         200, "\273",  # &raqot;
         201, "...",   # ellipsis
         202, "\240",  # &nbsp;
         203, "\300",  # &Agrave;
         204, "\303",  # &Atilde;
         205, "\325",  # &Otilde;
         206, "OE",    # OE
         207, "oe",    # oe
         208, "-",     # endash
         209, "--",    # emdash
         210, '"',     # open_qt
         211, '"',     # clos_qt
         212, "'",     # open_qt
         213, "'",     # clos_qt
         214, "\367",  # &divide;
         215, "*",     # diamond
         216, "\377",  # &yuml;
         217, "Y",     # Y.umlaut
         218, "/",     # fraction
         219, "ECU",   # circ.x    euro
         220, '<',     # open_qt   <
         221, '>',     # clos qt   >
         222, "fi",    # fi.lig
         223, "fl",    # fl.lig
         224, "++",    # dbldagger
         225, "\267",  # &middot;
         226, "'",     # under_qt
         227, '"',     # under_dqt
         228, "o/oo",  # per_mil
         229, "\302",  # &Acirc;
         230, "\312",  # &Ecirc;
         231, "\301",  # &Aacute;
         232, "\313",  # &Euml;
         233, "\310",  # &Egrave;
         234, "\315",  # &Iacute;
         235, "\316",  # &Icirc;
         236, "\317",  # &Iuml;
         237, "\314",  # &Igrave;
         238, "\323",  # &Oacute;
         239, "\324",  # &Ocirc;
         240, "*",     # apple
         241, "\322",  # &Ograve
         242, "\332",  # &Uacute;
         243, "\333",  # &Ucirc;
         244, "\331",  # &Ugrave;
         245, "i",     # dotless_i
         246, "^",     # circumflex  ^
         247, "~",     # tilde
         248, "\257",  # &macr;
         249, "\257",  # breve
         250, "\267",  # dot
         251, "\260",  # ring_above
         252, "\270",  # cedilla
         253, "\250",  # hung_umlaut
         254, "?",     # ogonek
         255, "?",     # caron
        );
    my $out = join("",
           map {exists $chars{ord $_} ? $chars{ord $_} : $_}
           split(//, shift @_)
          );
    $out;
}

1;