MARC::Charset(3pm)
π MARC::Charset π
okay bestie, so this is the User Contributed Perl Documentation page for MARC::Charset (the 3pm one, iykyk), and it's literally here to save your whole entire life if you've ever stared at a MARC bibliographic record and been like "why does this look like alien hieroglyphics". it's the glow-up from MARC-8 to UTF-8. we love to see it. π¦
β¨ NAME β¨
MARC::Charset β no cap, the whole job is: convert MARC-8 encoded strings to UTF-8. that's it. that's the gig. π
πΈ SYNOPSIS πΈ
here's the vibe, in code:
# import the marc8_to_utf8 function
use MARC::Charset 'marc8_to_utf8';
# prepare STDOUT for utf8
binmode(STDOUT, 'utf8');
# print out some marc8 as utf8
print marc8_to_utf8($marc8_string);
like, import the function, tell STDOUT to speak utf8, print your string. slay. π
π DESCRIPTION π
so MARC::Charset lets you turn MARC-8 encoded strings into UTF-8 strings. MARC-8 is a single byte character encoding that predates unicode (yes, it's giving ancient ancestor energy π§), and it lets you put non-Roman scripts into MARC bibliographic records.
the lore lives here, if you wanna read the actual spec:
http://www.loc.gov/marc/specifications/spechome.html
π«Ά EXPORTS π«Ά
β ignore_errors()
tells MARC::Charset whether or not to ignore all encoding errors, and returns the current setting. this is highkey helpful if you've got records that contain both MARC8 and UNICODE characters at the same time (messy, but we move).
my $ignore = MARC::Charset->ignore_errors();
MARC::Charset->ignore_errors(1); # ignore errors
MARC::Charset->ignore_errors(0); # DO NOT ignore errors
π¦ assume_unicode()
tells MARC::Charset whether or not to assume UNICODE when an error is encountered while in ignore_errors mode, and returns the current setting. again, super useful when your records are a little bit MARC8 and a little bit UNICODE. bestie it's a mixed bag out there. π
my $setting = MARC::Charset->assume_unicode();
MARC::Charset->assume_unicode(1); # assume characters are unicode (utf-8)
MARC::Charset->assume_unicode(0); # DO NOT assume characters are unicode
π assume_encoding()
tells MARC::Charset whether or not to assume a specific encoding when an error is encountered while in ignore_errors mode, and returns the current setting. helpful if you have records that contain both MARC8 and other characters. versatile icon behavior fr fr.
my $setting = MARC::Charset->assume_encoding();
MARC::Charset->assume_encoding('cp850'); # assume characters are cp850
MARC::Charset->assume_encoding(''); # DO NOT assume any encoding
π marc8_to_utf8()
converts a MARC-8 encoded string to UTF-8. the main character, honestly.
my $utf8 = marc8_to_utf8($marc8);
if you'd like to ignore errors, pass in a true value as the 2nd parameter, or call MARC::Charset->ignore_errors() with a true value:
my $utf8 = marc8_to_utf8($marc8, 'ignore-errors');
or
MARC::Charset->ignore_errors(1);
my $utf8 = marc8_to_utf8($marc8);
π utf8_to_marc8()
will attempt to translate utf8 into marc8. key word: attempt. she tries her best. π
my $marc8 = utf8_to_marc8($utf8);
if you'd like to ignore errors, or characters that can't be converted to marc8, then pass in a true value as the second parameter:
my $marc8 = utf8_to_marc8($utf8, 'ignore-errors');
or
MARC::Charset->ignore_errors(1);
my $utf8 = marc8_to_utf8($marc8);
π§ DEFAULT CHARACTER SETS π§
if you need to alter the default character sets (and honestly, sometimes you do), you can set the $MARC::Charset::DEFAULT_G0 and $MARC::Charset::DEFAULT_G1 variables to the appropriate character set code:
use MARC::Charset::Constants qw(:all);
$MARC::Charset::DEFAULT_G0 = BASIC_ARABIC;
$MARC::Charset::DEFAULT_G1 = EXTENDED_ARABIC;
periodt. that's how you customize the defaults. β¨
π SEE ALSO π
go read these next, bestie, they're all part of the friend group:
MARC::Charset::ConstantMARC::Charset::TableMARC::Charset::CodeMARC::Charset::CompilerMARC::RecordMARC::XML
π AUTHOR π
Ed Summers (ehs@pobox.com) β thank you for your service, legend. π«‘π
okay that's the whole page!! this was documented under perl v5.34.0, dated 2022-08-02, and honestly? iconic of it. go convert some character sets, you've got this. π
πΈπ¦
π¦ where this page comes from
- debian bookworm: libmarc-charset-perl 1.35-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmarc-charset-perl 1.35-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmarc-charset-perl 1.35-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmarc-charset-perl 1.35-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmarc-charset-perl 1.35-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms