Showing posts with label perl. Show all posts
Showing posts with label perl. Show all posts

Wednesday, February 9, 2011

how to force install perl module from cpan

perl -MCPAN -e "CPAN::Shell->force(qw(install IO::Socket::SSL));"


Thursday, September 16, 2010

how to update facebook status via command line

Recently, I found a text-based twitter client named "twidge".  It allows me to tweet right from command line.  For example, if you want to do a hello world tweet, you run this:

% twidge update "hello world"

I then think it would be a good idea if I can do the same thing with facebook i.e. to update facebook status right from command line.  However, when I did search on google, I found nothing.

Well, actually, there is an indirect way by:
  1. Adding facebook application "Selective Tweet".
  2. With the same twitter account you use to add "Selective Tweet", whenever you append "#fb" to your tweet, that tweet will also appear on facebook status.
But for many personal reasons, I just dislike this method as the same thing will be put onto both twitter and facebook which is not always what I want.

So what if I want to do it directly...

Recently, I had a chance to try out the Perl module "WWW::Mechanize" - Handy web browsing in a Perl object.  It is a subclass of the well-known LWP::UserAgent module which is a User Agent module for Perl which we use to write robot, spider and such.

Here is the Perl script I use to update facebook status:

#!/usr/bin/perl

use WWW::Mechanize;

$mech = WWW::Mechanize->new;
$mech->agent_alias('Windows Mozilla');

$base_url = 'http://m.facebook.com';

# {{{ login
$mech->get($base_url);
$response = $mech->submit_form(
  fields => {
    email => 'your_email_address',
    pass => 'facebook_password'
  }
);
die $response->status_line unless $response->status_line;
# }}}
 
while (1) {
  print "What's on your mind? : ";
  $status = <STDIN>;
  $response = $mech->submit_form(
    fields => {
      status => $status
    }
  );
  die $response->status_line unless $response->status_line;
}

Here is what you will see when you run it:

unsigned_nerd@linuxsucks ~ % fbset
What's on your mind? : it's easier to update facebook status from command line

By the way, isn't it better if I use some Facebook API instead...?  Umm... maybe later.

Tuesday, June 29, 2010

how to get perl module version

An easy way to do it is to use cpan:

$ cpan -D module_name

For example:

$ cpan -D HTML::Template::Extension

Thursday, June 3, 2010

tircd - url shortening

In tricd, a cool twitter client, if you want to use the url shortening feature, you need to make sure you have Perl module:

  URI::Find

One possible way to install this Perl module is by:

  perl -MCPAN -e 'install URI::Find'

This module is used by tircd to parse URLs from our tweets.

Monday, November 23, 2009

DBD::Oracle Perl Module returning data via refcursor bug - I have found a work around

DBD::Oracle Perl module, even with its latest version, still has a bug when we return data from Oracle to Perl via a refcursor. The problem is that it will be very slow because the driver does not perform the caching when fetching data from refcursor.

It will be very fast if the data are fetched through SQL SELECT statement, however.

I have found a workaround that you can apply it to your existing codes without having to modify your existing logics.

The workaround is to use Oracle's Global Temporary Table (GTT). And, inside your stored procedure, instead of fetching data into a refcursor, you change the code to fetch into your GTT instead. Then, in your Perl code, you modify the code so that it fetches the data from SQL SELECT statement. This way, you can fetch large data at a very fast speed.

GTT has a behavior that the data inside it are private for each different database transaction and will be emptied once your transaction ends or you force it to do so.


Woo Hoo!

Wednesday, August 12, 2009

Oracle limitation with Perl

Today is Mother's day in Bangkok. It's a holiday here, though, my mom has to work, still. I will have a dinner with her in the evening.

I just spent time today with nothing other than lying on bed and enjoying my new phone, the E71. This is my second E71 though. I lost my first one at a food stall. There are a lot of thieves in my country. I don't know whom to blaim. We just have to take care of our own safety all the time.

Now, it's time for writing down my next short note.

Oracle is a very expensive software. Its performance is very high, hence. However, when it works with other software component, we cannot expect to see the same result.

In my case, I use Perl with Oracle. Although the stored procedure in Oracle executes code very fast, when a large result is sent to Perl, who makes call to that stored procedure, it is crapping slow. The problem is that if a large result is transferred from Oracle to Perl by Oracle refcursor, it will be slow based on what kind of sql select query we use to fill that refcursor. Supposedly, I think the sql select query that at least one column is a result from a call to a function which inside that function has a call to something that also uses refcursor. This problem does not occur with Java though, for example. It looks like there are some bugs in DBD::Oracle perl module and the API Oracle provides to Perl. This issue has long been there for ages and noone is going to fix it yet.

To resolve this problem, there is a workaround that I also have applied to my project. By using a single sql select statement sending directly from Perl to Oracle to get a table through DBD::Oracle binding with data types other than refcursor. Then port the code in PL/SQL (stored procedure) into Perl. This way, the data transferring from Oracle to Perl will be extremely fast by comparing with returning data from stored procedure through refcursor. And that Perl is also super fast from its origin, the performance issue is resolved!

Friday, July 24, 2009

how to change cpan mirror list

$ cpan
cpan) o conf init

This will bring you to reconfigure everything.

Wednesday, June 3, 2009

How To Install Perl Module From CPAN

To install Perl Module from CPAN, please see an example below:
perl -MCPAN -e 'install Time::JulianDay'

How To Install GD Perl Module in Ubuntu Linux

# apt-get install libgd2-xpm-dev
# cd /root/.cpan/build/GD-2.35
# perl Makefile.PL -options "JPEG,FT,PNG,GIF,XPM"
# make<
# make test
# make install

Monday, June 1, 2009

DBD::Oracle Perl Module and Oracle - Versions

The truth is that DBD::Oracle 1.19 will work with Oracle 9i only.

Newer version of DBD::Oracle module will not be able to be compiled with Oracle 9i, unfortunately.

Wednesday, November 5, 2008

Shared object "libperl.so" not found, required by "plperl.so" in FreeBSD

If you get this error when you execute:

$ createlang plperlu some-database

-- [start: full error message] --
createlang: language installation failed: ERROR: could not load library
"/usr/local/lib/postgresql/plperl.so": dlopen
'/usr/local/lib/postgresql/plperl.so' failed. (Shared object "libperl.so"
not found, required by "plperl.so")
-- [end: full error message] --

You can simply execute:
# ln -s /usr/local/lib/perl5/5.8.8/mach/CORE/libperl.so /usr/lib/libperl.so