Posts tagged: perl

Late-Night PerlTK Fun.

I’m just messing around with PerlTK tonight. Here’s my artistic accomplishment.

#!/usr/bin/perl -w

use strict;
use Tk;

my($width, $height) = (250,250);
my $x;
my $y;
my $mw = MainWindow->new;
my $c = $mw->Canvas(-width => $width, -height => $height);
$c->pack;

$y = $height;

for ($x = 0; $x <= $width; $x+=10) {
	$c->createLine(0, $height-$y, $x, $height, -fill => 'blue');
	$c->createLine($width-$x, 0, $width, $y, -fill => 'black');
	$c->createLine($width-$x, 0, 0, $height-$y, -fill => 'red');
	$c->createLine($x, $height, $width, $y, -fill => 'green');
	$y-=10;
}

MainLoop;

Which results in

PerlTK is refreshingly simple to use. I recommend PerlTK.org to get yourself on your feet with a great tutorial.

SQLite and Perl

SQLite is a really cool utility. I just started using it with the Perl scripts that make up my NintendoDS WarDriving project. If you’re reading this, you probably want to know how to install the modules to get SQLite working with Perl (in a linux environment).

You’ll need two files for this. The first is the perl DBI (Database Interface) module. The current version, as of this writing, is DBI-1.607 (download).

The second file is the perl DBD-SQLite module. The current version is DBD-SQLite-1.14 (download).

Also, make sure you have build-essential installed! It is required for “make” and “make install”.

Before we start, it’s worth noting that SQLite is so small (around the 200KB range) that it is actually provided in the DBD-SQLite module. So you don’t need the “official” SQLite package installed on your system. The module is the only requirement to work with Perl.

Installation

DBI needs to be installed first. Unpack DBI-1.607

tar xzf DBI-1.607.tar.gz
cd DBI-1.607/

and then create the Makefile, run the make file, install and clean

perl Makefile.PL
make
sudo make install
make clean

And that is it for DBI. You can delete the DBI-1.607/ directory now, if you like.

cd ..
rm -rf DBI-1.607/

Next, do the same procedure for DBD-SQLite-1.14

tar xzf DBD-SQLite-1.14.tar.gz
cd DBD-SQLite-1.14/
perl Makefile.PL
make
sudo make install
make clean
cd ..
rm -rf DBD-SQLite-1.14/

And you are ready to rock and roll with SQLite and Perl.

An important lesson in saving…

…and backing up your saves in case you accidentally delete the copy you are working with.

Let this be a lesson to me. I was working tonight on the lottery simulation. I wrote some more code introducing new plotted data. All was well.

I thought maybe I’d take a break. I loaded up “20.000 Light Years in Space” and played a couple rounds of the beginner level.

I figured I’d had enough fun, it was now time to package up my hard work and post to the science page. I thought to myself, there’s no sense in tarring up all the results files, there’s a couple hundred of those and they are taking up way too much space!

Lesson: The ‘rm’ command is unforgiving.

I “permanently” deleted some of the new code I had written.

I know I could dip into the computer forensics field and recover my lost file, but it’s only 30 minutes of code I lost. 30 minutes is still an inconvenience. So be warned! Make sure you are rm`ing what you mean to rm.

I’m re-writing it now and it should be posted soon. I’ll update this post when it is.

[Edit]

I’ve fixed my mistake, the new code is better than it was before I erased it all. And now there are 979 new and updated files in the Lotto section. Perl really makes it easy to generate stuff. 979 files by hand? I wouldn’t bother.

Staypressed theme by Themocracy