Emacs, Perl

Emacs: align perl hash with align-current

I often write Perl script and use hash heavily. But I feel boring (and a little bit stupid) to align “=>” manually. For example, press SPACE to align

my %h =
    (
        key1 => value1,
        key11 => value11,
        key111 => value111,
    );

to

my %h =
    (
        key1   => value1,
        key11  => value11,
        key111 => value111,
    );

After reading Ruslan’s align-regexp, I find align-current and bind it to C-c C-c in cperl-mode.

(define-key cperl-mode-map "\C-c\C-c" 'align-current)

So, I can align those lines of Perl code simply by moving cursor to one of three lines and pressing C-c C-c.

Standard
Cygwin, Perl

Upgrade cygwin perl to 5.8.8-4

Cygwin perl is broken after I upgrate to version 5.8.8-4. Let’s fix it!

You have to remove Compress::Zlib first. Otherwise, cpan wouldn’t work.

$ rm -fr `find /usr/lib/perl5/ | grep Compress | grep Zlib`

Then, you have to recompile Scalar::Util yourself because weaken is not supported by default.

cpan[1]> force install Scalar::Util

Now, it’s time to upgrade CPAN.

cpan[2]> install CPAN

If you want Compress::Zlib back, remove IO::Uncompress::Inflate first. There is a circular dependence between IO::Compress::Bzip2 and IO::Uncompress::Inflate. Unless you remove this inconsistency, Compress::Zlib can’t be installed.

$ rm -fr `find /usr/lib/perl5/ | grep Uncompress | grep '\bInflate'`

Finally, I recommend you reinstall Bundle::CPAN and Bundle::Test.

Standard
Perl

Two Perl modules to handle table

I’ve been using Text::Table to output data onto screen and HTML::QuickTable into HTML file.

Text::Table can output data in table format with or without border which is composed of special characters. Here is an example:

use Text::Table;
my $sep = ' | ';
my $tb = Text::Table->new (\$sep, "Header", \$sep, "Index", \$sep);
my @data;
# ... fill @data
$tb->load (@data);
print $tb->rule('-', '+');
print $tb->title;
print $tb->rule('-', '+');
print $tb->body;
print $tb->rule('-', '+');

If you haven’t used this module, please try it to see what happens by filling dummy data into @data.

HTML::QuickTable is good at generating HTML table or entire HTML file from special data structure with little efforts. For example,

my @body;
while (<>) {
    chomp;
    my @row = split /,/, $_;
    push @body, \@row;
}
my $qt = HTML::QuickTable->new;
print $qt->render (\@body);

But it gives less control on table layout than HTML::Table. I will not give example since help is written well and its usage is simple.

Standard
Perl

Perl modules to generate HTML table

I don’t want to use XML::Writer to generate HTML table any more, so I search from CPAN and get following modules which can be used to generate HTML table. I list them here and will evaluate them later.

Standard