Perl Tips and Best Practices

- Get the absolute path and extract the basename. 

use Cwd;
use File::Basename;
​if( -e $modulesFile ){
    $modulesFile = Cwd::abs_path($modulesFile);
    $targetFile = basename($modulesFile);
}

-Filter out non-ascii characters , remain ascii characters only.

$tt =~ s/[^[:ascii:]]//g;

-Change the string's coding to utf8.

Encode::_utf8_on($chinese);

-Load properties files.

open DICT_PROPS, "< ".$dictionary_file   or die "unable to open dictionary";

my $dict_properties = new Config::Properties();
$dict_properties->load(*DICT_PROPS);
close DICT_PROPS;

$srcText= "Hello world!";
$theV =  $dict_properties->getProperty(Digest::MD5::md5_base64($srcText));