Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jplindstrom (594)

  (email not shown publicly)

Journal of jplindstrom (594)

Monday June 23, 2008
07:36 AM

5 and 6

Thursday June 19, 2008
11:00 AM

D'oh of the Day

So in the app at work, input is performed through what we call "an import".

Just now a strange error occured in the test that sanity checks that all modules compile.

Can't call method "request" on an undefined value

It appears I removed some duplication by extracting to a method called... "import".


See also:

perldoc -f use

Wednesday May 21, 2008
11:26 AM

Emacs Tramp syntax (for reference)

TRAMP is the Emacs feature that lets you edit files on other servers or as other users transparently. It's super convenient when you can't be arsed to drag the configuration all the way over there[1], or if Emacs isn't installed.

But I only need to every once in a while so I always forget the exact syntax even thought it isn't very diffcult.

Today I thought I had forgot it again, but instead I had been too clever with a socks configuration which prevented me to connect to otheraccount@localhost... Duh.

Anyway, when opening a file, just enter this:


and hit Tab to get file completion in the other account home dir.

Neato indeed.

[1] Yes, I know of -u to load .emacs from another account, but that often doesn't work out with the load paths, so TRAMP is actually easier if you don't need the version control integration, or flymake.

Tuesday May 20, 2008
08:16 AM

jQuery to the rescue (again)

If you do any kind of client side web programming, you should check out jQuery. Its pragmatic design is just awesome.

Today I had this Ajax response that I needed to parse to fetch an id so I could have the browser redirect to the correct URL.

Hmmm... how to work the xml? XPath? Fiddling with the DOM? I do that so rarely I can never remember the methods to call.

If only I could use the same simple jQuery approach!

Well, duh, it turns out I can.

var xml = $.ajax({ async: false, ... }).responseXML;
var import_id = $(xml).find("import").attr("iid");


Friday May 16, 2008
11:56 AM

10% at The Beeb

Interesting to read about Jonas's Google Day.

At the BBC we have what's called 10% time, which in our team translates to a Gold Card Day every sprint (i.e. one day in ten, which is... um... 10%).

"Gold Card", because we do Scrum and we put a card on the board for each developer. With the card we can do whatever we want for a day, but it's supposed to be somewhat related to the product, the project, or the team.

It's really good if it's also Innovative(tm).

Innovation is what the BBC is after. Apparently this is even in the BBC charter, and it's something that all of BBC is supposed to be doing. Currently I know of our team and another department doing it, but it's something they are semi-actively trying to get going all over the place at the moment.

When we started doing this Gold Card thing, it turned out that almost no-one actually took his Gold Card during scrum in the morning. So after a couple of weeks our Scrum Master instated the one "mandatory" day of do-whatever-you-want, which worked out very well. It's at the beginning of the sprint, so we don't risk putting it off at the end of the sprint because things may not be done (if that happens, we need to plan and estimate the sprints better).

So what kind of things are we talking about?

  • I spent last Gold Card creating a visualization of our code base as a clickable Treemap (I may turn that into a CPAN module in my own time. And replace that somewhat ugly JavaScript treemap with a prettier one). The Perl code stats collected so far are very naive, but here are some sample treemaps of our CPAN deps directory:
  • Way way back I wrote a tool to document and visualize database schemas. As a Gold Card task a month ago I adjusted the tool to MySQL and configured it for our code base so we get an automated SQL Map generated whenever the schema changes.
  • And the sprint before that, I spent Gold Card day investigating how Devel::Cover worked (yes, that took a day, more than that actually), making it possible to write Devel::CoverX::Covered and integrate it into Emacs with PerlySense (Ovid wrote Vim bindings).

While I tend to focus on tools and the dev environment and stuff like that, my team mates have investigated interesting and potentially useful technologies and done cool things to and with the product.

Edit: Added links to treemaps

Tuesday April 01, 2008
12:06 PM

Missing Perl::Critic plugins I: RequireElseAfterElsif

So this is a bug waiting to happen. Or at least a potential problem.

if ($period eq 'a') {
elsif ($period eq 'c') {
elsif ($period eq 'd') {


Well, if none of the if statements are hit, what should happend? Is it okay to omit that case, or is that in fact a bug because something didn't get handled?

Without reading and understanding the code you can't know whether the lack of an else clause is intentional or accidental. So it doesn't communicate intent clearly at all.

An empty else clause may seem redundant here. And it is redundant. To the compiler. But it communicates to the maintenance programmer: yes, I actually thought if this case too.

But, my experience is that whenever there is an elsif chain without a final else clause to catch all remaining cases, that is often a bug. The missing else clause leads to something not happening at all.

Sometimes the missing else clause is not a bug right now. One of the elsif clauses will always hit given the current input. But if anything related to producing the input changes (somewhere in a distant corner of the code base, far away) then this piece of code suddenly breaks. Silently.

At the very least, there should be a guarding else clause which says

die("Internal error, sanity check failed: blah blah blah");

So, dear Lazyweb, please write Perl::Critic::Policy::ControlStructures::RequireElseAfterElsif for me.

Or else.

Tuesday February 26, 2008
05:17 AM

Howto: Install local dist file using the cpan shell

Gaah. I forgot it. Again.

When you have a downloaded tar ball of a CPAN package, but want to use the properly configured cpan shell to install it (and get dependencies nicely resolved):

  • Unpack the tar ball
  • cd into the dir
  • cpan .
  • Coffee time!
Tuesday January 29, 2008
06:54 PM

Emacs: Debugging elisp

In elisp, Data::Dumper is spelled prin1-to-string. Nicely pretty-printed output of deep data structures. Invaluable when you're, like me, lost in the details of Emacs' (and your own for that matter) data structures.

(message "thing: <%s>" (prin1-to-string thing))

Note 1: (message) takes a string like (format) does, which means that if your string value contains e.g. %s... well that's bad. So you should always do (message "%s" my-string).

This is documented but easily overlooked because (message) is one of the first basic tricks you acquire when you start coding elisp, usually by looking at existing code. And then you think you know how it works. At least, that's how I did it.

I used to write (message (format "blah" stuff)) for a while before I finally read the docs for it.

Note 2: The < > in the example is an old habit of mine: always always always put visible delimiters around variable output in log messages so that you immediately see when the value contains padding whitespace.

Yeah, trouble shooting weird errors is easier if you see what you're looking at.

Monday January 21, 2008
07:03 AM

MySQL: error 150 on rename column

Dear Google Search Result Page!

So this fails on an InnoDB table in MySQL 5.0:

ALTER TABLE `xxx_table`
    CHANGE COLUMN `importid` `import_id` int(11) NOT NULL;

with this luvely error message:

#   Failed test 'Migrating up to 29 '
#   at t/unit/db/migrations.t line 84.
ERROR : DBD::mysql::db do failed: Error on rename of
'./xxx_tmp_migration_test_1200915479/#sql-4dcf_348f2' to
'./xxx_tmp_migration_test_1200915479/xxx_table' (errno: 150)

Why is this?

At first I thought it was because importid is part of the composite PK (it's a link table), but that's not it.

It turns out that there is a FK constraint on importid to another table. Deleting the FK and reinstating it with the new column name solves the problem.

Thanks for the self explanatory error message MySQL, that was very helpful.

Sunday January 20, 2008
08:45 PM

Emacs: latest habits: regex-tool and Visible Bookmarks

Using Emacs means constantly acquiring new habits to improve how you do things.

Well, maybe not constantly. It's important to let the good habits slowly grow into reflexes, otherwise it's just too much to think about when you try to get things done. Once it's a reflex you can forget about it, just use it and work on picking up the next useful trick. Fortunately that seems like a renewable resource.

Last week I picked up something I've lacked for a while: Visible bookmarks. I know of putting locations in registers, but I never really started using that for some reason. I think it was ever so slightly too bothersome to use, and so I didn't. We'll see if I have started using these in a week or two, or if I need something else from it.

The second new thing is the Regex Tool which will let you compose a Perl (or Emacs, but we already have re-builder for that, so...) regular expression interactively with matching text highlighed. If you have seen The Regex Coach, this is pretty much it.

This is obviously a very useful thing to have when writing complicated regexes.

I just uploaded the latest release of Devel::PerlySense to PAUSE. Release 0.0141 bundles regex-tool.el and contains a first stab at integrating it with PerlySense. Well, integrate and integrate... The default dialect is set to Perl, and it's got a key binding :) That's about it at the moment.

The next step is to notice if point is on a regex and use that as a default.

The next next step is to notice whether there is a comment block just above the regex. If there is, it will be assumed to be an example of the text to match and used as the default.

I've found that putting the example input next to the regex to be a very good practice; it really helps understanding what the regexp is all about when coming back and reading it three months later. Yeah, yeah, there should be complete sample input in unit tests, but those are in a different file, and you may not know about it (or whether it actually exists) when you come across this piece of code. So it's good to have it right there. The Principle of Proximity in action again.

In the process of incorporating Regex Tool I also upgraded it a bit to support the whole Perl regex syntax with modifiers (including the essential /x). I hope the author will accept a patch.