FIX_LATIN(1p)

πŸ“¦
version 1.04 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– 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 UTF8 characters 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: that 0x80–0x9F zone is where CP1252 lives, and 0xA0–0xFF is 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 underlying Encoding::FixLatin and XS modules. 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 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