FIX_LATIN(1p)
π FIX_LATIN β¨
okay bestie, so <rainbow>fix_latin</rainbow> is this lil filter script (it lives in the perl manual pages, section 1p) that takes a data stream which is mostly utf8 and fixes any latin β aka non-ASCII 8-bit β characters that are lurking in there. it's giving cleanup crew energy fr fr. π§Ήπ
β¨ SYNOPSIS β¨
fix_latin options <input_file >output_file
Options:
--use-xs <value> 'auto' | 'always' | 'never'
--version list version number
--help detailed help message
like, you feed it stdin, you get stdout, the options are just vibes on top. π
πΈ DESCRIPTION πΈ
the script is a filter. you hand it source data that might be a whole chaotic mix of ASCII, UTF8, ISO8859-1 and CP1252 characters β no judgment, we've all been there β and what comes out the other side is all ASCII/UTF8. glow-up complete. π
here's the tea on how each byte gets treated:
- Multi-byte
UTF8characters get passed through untouched β¨ (with one tiny caveat: over-long UTF8 byte sequences get converted to the shortest normal form β so they get tidied up, not left messy). - Single byte characters get converted like this:
0x00 - 0x7F ASCII - passed through unchanged
0x80 - 0x9F Converted to UTF8 using CP1252 mappings
0xA0 - 0xFF Converted to UTF8 using Latin-1 mappings
bestie note: that0x80β0x9Fzone is where CP1252 lives, and0xA0β0xFFis Latin-1 territory. the script knows which is which, you don't have to. π«Ά
π OPTIONS π
--use-xs'auto'|'always'|'never'β this overrides the default<purple>'auto'</purple>behaviour, which is: try to use the XS module, and if it's not there, gracefully fall back to the pure-Perl version. set it to'never'and you'll always use the Perl version. set it to'always'and you'll always use XS β and die if it's not available. no fallback, no mercy, periodt. π--version(alias-v) β prints the version number of the underlyingEncoding::FixLatinandXSmodules. receipts, basically. π§Ύ--help(alias-?) β shows you this documentation. hi, you're reading it. π
π¦ EXAMPLES π¦
fun fact: this script was originally written to help convert a Postgres database from SQL-ASCII encoding to UNICODE UTF8 encoding. iconic origin story honestly. the examples below show it doing exactly that.
if you've got a SQL format dump file that you'd normally restore by piping straight into psql, you can just run the dump file through this script first:
fix_latin < dump_file | psql -d database
if your dump file is compressed and you'd normally restore it with pg_restore, you can drop the -d option on pg_restore and pipe the resulting SQL through this script and into psql:
pg_restore -O dump_file | fix_latin | psql -d database
and if you just wanna snoop at the non-ASCII lines in a dump file, this one's for you:
perl -ne '/^COPY (\S+)/ and $t = $1; print "$t:$_" if /[^\x00-\x7F]/' dump_file
π SEE ALSO π
this script is implemented using the Encoding::FixLatin Perl module. for more deets, read the module documentation with:
perldoc Encoding::FixLatin
and specifically, bestie, go read the 'LIMITATIONS' section, because that's where it explains the circumstances under which data corruption might occur. like β read it. fr fr. don't skip it. π
π COPYRIGHT & LICENSE π
Copyright 2009-2014 Grant McLean "<grantm@cpan.org>"
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's a wrap!! π this page came to you from the user contributed perl documentation, version perl v5.40.1, dated 2025-08-04 β tysm for reading, go fix some latin, slay. πβ¨π¦
π¦ where this page comes from
- ubuntu resolute: libencoding-fixlatin-perl 1.04-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libencoding-fixlatin-perl 1.04-5 Β· 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