invalid byte sequence for encoding “UTF8″: 0×8b – storing binary data

This error message took me lots of effort and time to solve it. The problem is that before storing binary data strings in the postgresql database the binary strings need to be escaped before storing them. There is on the google available subroutine for per which is doing this job. It is called escape_bytea. Anyway [...]

Create and install linux debian package for missing perl module with dh-make-perl

Sometimes you encounter situation when you need a perl module to support your program but perl module is not available from standard linux repositories. Installing perl module from source code is not always good idea so what would be the best is to create package for a particular module using dh-make-perl command. In my case [...]

Perl script code example to create temporary file-tempfile()

Here is a perl script example how to create temporary file on the file system:
TEMPLATE DIR AND SUFIX are option !

#!/usr/bin/perl
my $tempfile = new File::Temp ( TEMPLATE => ‘tempfile_XXX’, DIR => ‘/tmp/’, SUFIX => ” );

this will create a temporary file in /tmp/ directory with name tempfile_XXX where X is random generated character.

Perl script code example to create temporary directory-tempdir()

Here is a perl script example how to create temporary directory on the file system:

#!/usr/bin/perl
use File::Temp qw/ tempdir /;
my $perl_temporary_directory = tempdir();

Basic example of simple C program include static library compilation-source code

install gcc compiler:
apt-get install gcc
All following steps are done in the same directory !! NO need to have an root permissions.
create library1 and save it as liblibrary_1.c:
#include
void library_1(char *val)
{
printf(“Passed value to library_1: %s\n”, val);
}
create library2 and save it as liblibrary_2.c:
#include
void library_2(char *val)
{
printf(“Passed value to library_2: %s\n”, val);
}

Compile both c libraries source codes:
gcc -c liblibrary_1.c liblibrary_2.c
NOTE: [...]

My First Linux C Program Example- Hello world

Here is how you can create linux hello world program. First make sure that you have gcc ( c programming language compiler ) package installed. On debian or on ubuntu you would do:
apt-get install gcc
save this code as linux_program_hello.c
#include
#include
int main()
{
printf(“My First Linux Program – Hello World\n”);
exit(0);
}
now its compile time:
gcc -o linux_program_hello linux_program_hello.c
run your first c [...]

Invalid command ‘PerlHandler’ – PerlHandler ModPerl::Registry

Apache complains on the restart:
/etc/init.d/apache2 restart
Forcing reload of web server (apache2)…Syntax error on line 48 of /etc/apache2/sites-enabled/000-default:
Invalid command ‘PerlHandler’, perhaps misspelled or defined by a module not included in the server configuration
failed!
Have a look what perlhandler it is in apache config file. In this case apache was missing : ModPerl::Registry .
Solution to this is to [...]

Debian apache problem – [error] Can’t locate Apache/DBI.pm in @INC

Debian Apache will not start and it complains in log file:
[error] Can’t load Perl module Apache::DBI for server exiting…
This is because it can not find perl module which apache will use to connect DBI database. Solution for this is to install package:
libapache-dbi-perl – Connect apache server to database via perl’s DBI
apt-get install libapache-dbi-perl

CREATE, INSERT, SELECT, UPDATE Perl script and PostgreSQL database examples

Simple perl to postgresql examples:
#!/usr/bin/perl
#load perl postgresql module
use DBI;
$postgresql_database=yourpostgresdatabase;
$postgresql_user=yourpostgresuser;
$postgresql_password=yourpostgrespass;
$postgresql_host=localhost;
# connect to perl to postgresql database
my $dbh = DBI->connect(“DBI:Pg:dbname=$postgresql_database;
host=$postgresql_host”, “$postgresql_user”, “$postgresql_password”);
# EXAMPLE PERL and POSTGRESQL
# CREATE TABLE EXAMPLE
$sth = $dbh->prepare(“CREATE TABLE perl_postgres
( language varchar(40), version integer);”);
$sth->execute();
# EXAMPLE PERL and POSTGRESQL
# INSERT DATA INTO TABLE
$dbh->do(“INSERT INTO perl_postgres(language, version)
VALUES (?, ?)”, undef, (‘perl’, 5)) or die (“Cannot INSERT”);
# [...]

Match / validate an email address with Perl regex ( regular expression )

Match or validate an email address with perl regex ( regular expression )
This perl script shows how to validate an email address using perl and regular expression ( regex ).
#!/usr/bin/perl
@email = (“email\@address”,”email\@address.email”,
“\@address.email”,”address.email\@email”, “validate\@email.address”);
foreach (@email) {
if (/^[A-z0-9_\-]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{2,4}$/) {
print “$_\n”;
}
}
Result:
email@address.email
validate@email.address