Stories
Slash Boxes
Comments
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 ]

hex (3272)

hex
  (email not shown publicly)
http://downlode.org/

Perl, RDF and wiki hacker, London, UK. This is my former Perl blog; I now write at Earle's Notebook [downlode.org].

Journal of hex (3272)

Thursday April 14, 2005
07:04 AM

Problem with numeric scalars in an SQLite DB

My module Locale::Object comes with an accompanying SQLite database that contains a bunch of locale information. Since I released it, SQLite has had a major upgrade from v2.8 to v3.0 and the database format has completely changed. So, I'm in the process of making a new release with a db file in the new format. (I should have done this earlier, actually, since I've had a couple of emails about it. My apologies to anyone I've inconvenienced.)

Thing is, I've hit a problem. The process of dumping the old database and reading it into the new format by doing sqlite OLD.DB .dump | sqlite3 NEW.DB worked just fine. However, some of my data changed.

Some of the tables in the db contain a bunch of three-digit ISO codes used to identify countries and so on. Quite a few of these codes start with a zero. On checking the newly created database with sqlite, though, I discovered that all the leading zeroes had vanished.

Talking to DrForr on #perl, I discovered that SQLite now has a concept of column types, and so I recreated the tables in question, changing the columns to be TEXT char(3), thinking that this restriction would force it not to consider the values as numbers. But that didn't work:

foreach (@rows)
{
  my ($code_alpha2, $code_alpha3, $code_numeric, $name, $dialling_code) = @{$_};
 
  # Yes, this is crap, but I don't care right now:
 
  $code_numeric = '0' . $code_numeric if length($code_numeric) == 2;
  $code_numeric = '00' . $code_numeric if length($code_numeric) == 1;
 
  print "country: $code_alpha2 / $code_numeric\n" if $code_numeric =~ /^0/;
 
  my $sth_update = $dbh_new->prepare("INSERT INTO country VALUES (?,?,?,?,?)");
 
  $sth_update->execute($code_alpha2, $code_alpha3, $code_numeric, $name, $dialling_code);
}

The kind of stuff that gets printed to STDOUT is country: bm / 060, but when I check the database in sqlite, it says bm|bmu|60|Bermuda|1441. Still stripping the zeroes!

I've tried a few different approaches, but none have worked. Leon suggested overloading "" to force stringification(?), but I'm finding it extremely hard to understand either what perldoc overload or the Camel have to say about overloading.

Can any of you help?

Friday August 27, 2004
10:07 AM

Zen Buddhism makes a stand on Perl data structures

(originally posted to a Fotango mailing list, but I thought it merited going here as well)

From The Manual of Zen Buddhism:

"Subhuti, what do you think? Does a Bodhisattva set any Buddha-land in array?"

"No, World-honoured One, he does not."

"Why? Because to set a Buddha-land in array is not to set it in array, and therefore it is known as setting it in array."

I trust that is sufficiently clear.

Sunday April 25, 2004
05:06 PM

Palindromy

On #perl a few minutes ago people were making up palindromes. I just want to record my contribution before it scrolls away and is lost: Fool, repair an aria. Perl? Oof!
Monday March 01, 2004
01:31 PM

Use it wisely, my son!

The blurb of PERL from the GROUND UP [sic] reads:

Open this Book as a Novice
and Finish it as a Pro

Discussed this with richardc. Questions we thought needed answering:

  • If you start reading it as a Pro, will it immediately turn you back into a Novice?
  • Can you save time by just reading the end and become a Pro right away?
  • What happens if you read it backwards? Will it drain out all your knowledge?

I was reminded for some reason of the bit of Raiders of the Lost Ark where the spirits come out of the Ark of the Covenant and melt people's faces off. We decided in the end it was safer not to open the book at all.

12:10 PM

Leaner. Cleaner. Meaner. Wikibot 0.5.

At long, long, long last, I've done the rewrite of Wikibot to use Bot::BasicBot. I've been meaning to do that for a year and a quarter. This means two things:
  • I'm no longer ashamed to say "Yes, that's my code." (I wrote most of it way before becoming a professional Perl programmer, when I didn't know shit from Shinola.)
  • The probability of upgrades and extensions just skyrocketed.

Bot::BasicBot really is so cool. My thanks to all those involved.

Monday February 23, 2004
10:10 AM

Holy smokes

If you know me I've probably already babbled to you about this, but:

Dear Open Guides Team,

We would like to invite you to participate with http://openguides.org/ in this year's Prix Ars Electronica, the foremost international prize for computer-based art.

Top prize: EUR10,000!

Crikey.

Monday January 26, 2004
09:02 AM

DateTime::Format::IBeat

Dave Rolsky has just given me maintainership of DateTime::Format::IBeat, one of Iain's modules, so I've released version 0.161 to update the maintainer info. I'll probably mark Time::Beat as being superseded by it at some point.

I'm honoured to be looking after Iain's code, and I just hope that I do it justice. Requesciat in pace, koschei.

Tuesday January 13, 2004
06:11 AM

Curious dependencies in DateTime

richardc - our release manager here at Fotango - just came over to tell me that our build system was choking whilst running the tests for Locale::Object . After a bit of poking around, we traced the problem down to DateTime::TimeZone , which L::O uses.

It turns out that the build was croaking because when Locale::Object::Country did a DateTime::TimeZone->new(), it needed DateTime . However, my Build.PL doesn't list DT as a pre-req, because DT::TZ doesn't either. Combing through the code, we discovered that DT::TZ has an implicit requirement for DateTime because DateTime::TimeZone::OlsonDB does a DateTime->new() . Not a problem, you'd think, right? Add a dependency for DT. Unfortunately, DT depends on DT::TZ.

Our "solution" was to skip tests for DT::TZ. Not ideal. Anybody have any experience of dealing with this kind of thing?

Friday December 05, 2003
06:10 AM

Rubbish

So I'm looking into writing Locale::Object::AddressFormat to go into the next release of Locale::Object and provide data on the format of postal addresses in different countries. Whilst searching, I found the Universal Postal Union's addressing formats guide. That should be perfect! Right? Wrong. Instead of having a big, easily parseable table of formats, or even collection of little pages with formats in them, you get a drop-down menu to select the country you want - and when you press the "Display" button, it sends you a freaking Microsoft Word document. With about twenty words in it. It doesn't even say on the page that it's going to do this, it just assumes you're OK with it. What a turd of a website - and to think, this is the people who deal with our mail. Jeez.
Tuesday December 02, 2003
09:46 AM

Bandwidth dickwaving

The TOAST.net Performance Test says 3230K for us here at Fotango. How about you?