Information Technology Grimoire

Version .0.0.1

IT Notes from various projects because I forget, and hopefully they help you too.

Check Supported Encoding Types Using Perl

When working with ascii files, csv and other text format files you will often need to know the encoding that your system supports and the encoding of the file you are working with.

You can guess, or you can just ask the OS. Here is what my system supports natively

Sample Encoding List

  • ascii

  • ascii-ctrl

  • cp1252

  • iso-8859-1

  • null

  • utf-8-strict

  • utf8

Perl Script to Check Supported Encoding

#!/usr/bin/perl

use warnings;
use strict;
use Encode;

my @list = Encode->encodings();

foreach my $enc (@list) {
	print $enc . "\n";
}

Use Perl to Guess Encoding

There is a perl module already for this, and you must supply it with the proper choices to guess from.

Use Command Line to Guess Encodings

This is a binary on linux (and cygwin) called “file”. It will help determine file types. However, it’s not entirely accurate and like all guesses, it’s a “guess”.

(1:597)# file test*.*
testfile.txt:  ASCII text
testscript.sh: Bourne-Again shell script, ASCII text executable

The above script is just one tool in a series of tool kits needed to help troubleshoot encoding issues.

Last updated on 26 Jul 2019
Published on 26 Jul 2019