Tuesday, April 23, 2013

mysql hack -- some tips..!

1- Mysql engine selection

MySQL uses row-level locking for InnoDB tables to support simultaneous write access by multiple sessions, making them suitable for multi-user, highly concurrent, and OLTP applications. MySQL uses table-level locking for MyISAM, MEMORY, and MERGE tables, allowing only one session to update those tables at a time, making them more suitable for read-only, read-mostly, or single-user applications. " @http://dev.mysql.com/doc/refman/5.5/en/internal-locking.html

hack perl...! some tips

1- utf-8 encoding and decoding

      'lc' do not support utf-8 characters directly.Hence below solution

        use Encode qw(encode decode);
        $word_key=decode('utf-8',$word_key);
        $word_key=lc($word_key);
        $word_key=encode('utf-8',$word_key);
     

2- Wide character print error
     Please encode the data than print it.

3- unicode to perl character

     my $string = "Hello \x{263A}!\n";
    @arr= split //,$string;
     print "@arr";

4- Read a file which has mixed characters ( ASCII and Unicode codes in the form of $<4-hex-code>) and then convert them to lowercase

#!/usr/bin/perl
use utf8;
use Encode;
open $file,'<:utf8','sample';
while(<$file>) {
s/\$(\p{AHex}{4})/chr hex $1/eg;
#s/\$(....)/pack 'U4', $1/eg;   /// this wont work
$_=lc($_);
$_=encode('utf-8',$_);
print;
}

#!/usr/bin/perl
=pod
$line = 'i m gaurav $0040 pant';
$line =~ s/\$(\p{AHex}{4})/chr hex $1/eg;
print $line;
=cut
#$line = 'i m gaurav \u0040 pant';
$line = 'T\u1ea5t c\u1ea3';
$line =~ s/\\u(\p{AHex}{4})/chr hex $1/eg;
print $line;
~