Gist of the Day: Named Capture in Perl Regular Expressions (Briefly)

One of the largest critiques I see about regular expressions is that they lack readability. Well, in Perl 5.10 named capture was added (http://perldoc.perl.org/perlretut.html) which I think adds an awful lot of readability to Perl regular expressions. Continue reading Gist of the Day: Named Capture in Perl Regular Expressions (Briefly)

Gist of the Day: Using Mojo, Mongo, and SL4A to send SMS Messages (1 of 2)

I got a little bored with what I had been posting (I suspect you did, too), so I’m doing something neat. I’m going to write a full (though limited) program for you. Here are the user stories (if you don’t know what user stories are, see here before continuing):

Gist of the Day: Find All Paths for an Undirected Graph

I’ve been doing a lot of stuff lately with data structures and algorithms. This is one that seemed remarkably complicated to me – and still kinda does – when I started. It’s not as trivial as a binary tree mainly because there are far fewer rules. There’s a whole lot of stuff you can do with graphs, and this is by no means an advanced or complicated usage of them. This is as simple a task you can do with a graph.
The task at hand is to find all possible paths between two vertices. Continue reading Gist of the Day: Find All Paths for an Undirected Graph

Gist of the Day: Re-Inventing Hashes… In Perl.

Before you begin the well-deserved flaming, please understand that I do not intend on submitting this to CPAN. This is purely an academic exercise to demonstrate the algorithm (poorly), and to help me practice some stuff. I understand that this isn’t terribly efficient, and I am quite confident that one could do this much faster (and probably has many times over). I wrote this for fun, and for boredom, and I’m posting it because I thought it was cool and because I promised you I’d post stuff.
This algorithm is pretty simple. The premise is that you take a key value of some sort, you hash it using any algorithm, and then you take the mod of that hash value by the capacity of your hash table, and that gives you an index! It’s pretty simple, and even in the implementation I have here I believe it’s not a terrible look-up time.
The basic idea is this: $array_index = hashval($key) % $array_capacity
Continue reading Gist of the Day: Re-Inventing Hashes… In Perl.

Gist of the Day: Process Control with fork(), exec(), and kill()

I feel really bad for leaving you all high and dry yesterday… really bad… okay, you’re right, I don’t really feel all that bad.
I have a doosey for you all today though, no doubt about it! One of the most common trends in computers these days is multi-processing. Multiple cores means one program can do more work by spawning extra threads or child processes. I’ve already done a bit of stuff with threading, so here’s a bunch of stuff with forking (tee-hee). Continue reading Gist of the Day: Process Control with fork(), exec(), and kill()

Gist of the Day: Analyzing Performance with Benchmark.pm

In my post on Inline::C a few days ago I mentioned The Rules of Optimization Club, and then I ranted a little bit about how if you cannot measure a performance problem then you don’t have a performance problem. That’s not to say that you’re incorrect in asserting that you have a performance problem, it is only to say that you cannot identify any particular part of the problem as a performance problem until you have measured it.
There a great number of ways to measure performance problems, profiling probably being the most useful in situations involving large applications where you want to test performance under real-life situations. For profiling, I would recommend you look at Devel::NYTProf. This profiler is exceptionally feature-rich and has a boatload of useful functionality. All that said, here I’m only going to talk about bench-marking small pieces of code. Continue reading Gist of the Day: Analyzing Performance with Benchmark.pm

Gist of the Day: Some convenience macros for use with Perl C internals

I feel awful. Like, really awful. The baby is sick, my partner is sick, I am sick. You still want something neat though, so I’m going to show you something very simple that I’ve used for a while.
As I’m sure you noticed in yesterday’s Inline::C demo, Perl guts and C API are pretty noisy with a lot of boiler-plate. For this reason, when I first started playing with Perl guts and API, I created a header file just to make things a little simpler. Nothing here is terribly complicated, and they’re all just simple convenience macros, but sometimes that type of macro saves you oodles of time. Continue reading Gist of the Day: Some convenience macros for use with Perl C internals