July 2010 Archives

Insight on SWIG?

SWIG is available for some time to create bindings automagically for C and C++ applications. It supports code generation in different languages, including Python, TCL and Perl.

Curiously, in my years of Perl community I can't recall a talk on a YAPC about SWIG, and I can't recall any post on the usual community blogs about it as well. I would be grateful if any experienced XS user could comment on how good (or filth) is this tool and the generated bindings.

Using Skels

This time I am writing mainly for beginners, and not specifically for Perl programmers, but any programmer of any language. Skels (my abbreviation for skeletons) are totally relevant in a programming environment.

What are skeletons? There are different names for the same thing. You can call it a template, or call it a snippet. Skels, for me, are both: pieces of code, that might work or not, that might have placeholders or not, but that save you time by remembering how something is done.

I have a bunch of skeletons ready to use in my Emacs. I would like to have more, but some…

Combinatory Substitution

Not sure if the title is understandable. But I will give an example. Consider a word (well, invented one): noogoo. Now, consider you want to do all possible combinations substituting oo with aa, that is, generate naagoo and noogaa.

The solution I am using, that was idea of my friend Luciano, is as follows:

    $word = "noogoo";
    push @where, pos($word)-2 while $word =~ /oo/g;
    for my $i (@where) {
        my $other = $word;
        substr($other,$i, 2, "aa");
        push @words, $o if $o ne $word;
    }

Any better or more efficient idea?

Growl from command line

I am a Mac OS X user, and I like Growl. To see notifications can be irritating, sometimes. Irritating and distracting. But this doesn’t mean the tool is not useful.

And I find it useful when processing large quantities of data, and when this process is split in different small processes. In these cases, I like to have Growl warning me about what stage of the process is starting/ending and, when it finishes, to have a final warn about it.

While I can use Growl directly from Perl, that doesn’t work easily when using makefiles, for instance. Then, I wrote a small script that I put into my user binaries folder, and that reads the message from the command line, just like:

 growl Hello World!

In case someone finds this code useful, here it is:

#!/usr/bin/perl
use Mac::Growl ':all';
RegisterNotifications("Command Line", ["Note"], ["Note"]);
PostNotification("Command Line", "Note", "Note", join(" ", @ARGV));

Modules and commands with same name

Today I noticed that I had a module outdated, named Starman. I have no clue about what it is (ok, now I have), so I typed 'perldoc Starman'. My Mac OS X is not case sensitive (unfortunately). This resulted in the documentation of the command 'starman' to be shown. The man page says "see also, Starman".

Now, the question is... how can I get the documentation for the module, using perldoc?

TPF 2010Q3 Request for Grant Proposals

The Perl Foundation is looking at giving some grants ranging from $500 to $3000 in August 2010.

In the past, we've supported Adam Kennedy's PPI, Strawberry Perl and Perl on a Stick, Nicholas Clark's work on Perl internals, Jouke Visser's pVoice, Chris Dolan on Perl::Critic and many others (just check http://www.perlfoundation.org/grants for more references).

You don't have to have a large, complex, or lengthy project. You don't even have to be a Perl master or guru. If you have a good idea and the means and ability to accomplish it, we want to hear fr…

About Alberto Simões

user-pic I blog about Perl. D'uh!