scoping

As per my previous post, I thought it would be a good to try generating the filename of the output file based on the name of the source file. The tricky bit ended up being mostly easy, and the easy bit ended up being tricky. Unsurprisingly there’s a module devoted to splitting up filenames and thus, this resulted in my first use of a module as well:

use File::Basename;

followed by:

my $basename = basename($source, “.csv”);

the use of which in this instance, is based on the assumption that the source file is a .csv file (Comma Separated File). It takes the source name eg snailsource.csv and strips off the .csv. I create the new filename such:

$result = “$basename.txt”;

which results in snailsource.txt. it really was as simple as expressing the new name by adding “.txt” to the $basename variable. I suspect I could have called the “$basename” variable $snailsource or $filename etc.

What I hadn’t realised was that variables are “scoped” and are only recognised within the {} of your subroutine if they have not first been declared outside the subroutines. I eventually worked that out, through Perl Maven’s article. The hard bit was trying to understand why it still didn’t work. I spent an hour on Friday night getting nowhere then looked at it at the start of lunch today and had it solved in a couple of minutes.

Turns out that I’d been under the assumption that I needed to assign values to variables using “my” so the original version of the above line was:

my $result = “$basename.txt”;

within a {…} subroutine. I removed the “my” and it worked.

My little program now checks for 2 arguments, and if there is 2 arguments (source and output files), it sends the results to the specified output file. If there is only 1 argument (the source file), it generates the name of the output file using the name of the source file.

Posted in tech | Leave a comment

another step

I had another idea regarding my little perl program which meant I learnt a little more. I thought it would be nice if the program could write the list of barcodes to a file as currently it sends them to the screen along with the final count. This meant I needed to learn how to use perl to create a file and write to it, from within the program. This turned out to be fairly easy as I’d already learnt some file handling last week in order to read data from a file.

I included checks to see whether a filename was passed as one of the arguments and if not to halt, with an indicative message. This version of the program will only successfully run if there are calls to a source CSV file and a text file is named for output. I s’pose the next step would be for it to generate a filename, based on the source file, if there is no output file included.

It had not been my intention to learn perl. I had planned to learn python but a task came up and I knew more about perl than python so I did it that way and it worked. I recall from my old computer engineering days that a good way to compare languages and learn their strengths and weaknesses, is to write the same program in each. I may give this a go when I’ve developed my barcode handler a little further.

Having registered for a course online with the hope that that would inspire me to learn, instead it’s more the case that I required a problem to solve in order to commit myself. Solving that problem in turn led to other possibilities to develop. I now have a few simple programs doing a couple of different actions on the same data and already I’m thinking that later, I should turn them into one program that does all that and more. At some point along the way, it would be good to develop a web interface and make it easier for other people to run the same reports.

Early days but clearly, I am having fun :-)

Posted in tech | Leave a comment

reading nice things

Fetish for nice things aside, I’ve been looking at all my books and particularly the dodgy, old paperbacks. There are particular gems among them and I thought it would be nice to have nice editions and get rid of the increasingly fragile/deteriorating copies. While reading about some of the nice editions that Easton Press do, I happened to come across a few copies that they published of Clifford Simak‘s work, Way Station and City. I dutifully ordered both and they’ve been sitting on the shelf for the last couple of months.

A couple of nights ago, I picked up Way Station and started reading it again. Once again it grabbed me right from the start and I was reminded of how much I love the flow of Simak’s writing and his treatment of science fiction incorporating believable approaches to technological developments. I recall reading him voraciously, and ending up with a collection of 20 or so of his novels secondhand. Way Station and City are regarded as two of his best.

The Easton Press editions are nicely bound in leather, with gilt edging and a bound ribbon marker. Having recently picked up a splendid edition of Ender’s Game by Orson Scott Card from Centipede Press, I’m looking forward to re-reading it too. I’ve come across a list of the Easton Press SF editions and already spotted a couple on AbeBooks. I don’t want them all but there are several at least I may well acquire at some point including:

  • A Canticle for Leibowitz by Walter M. Miller, Jr.
  • The Day of the Triffids by John Wyndham
  • The Dispossessed by Ursula K. Le Guin
  • Dune by Frank Herbert
  • Earth Abides by George R. Stewart
  • Fahrenheit 451 by Ray Bradbury
  • The Foundation Trilogy by Isaac Asimov
  • More Than Human by Theodore Sturgeon
  • Solaris by Stanislaw Lem

One book I’d like but left off the list above is “Do Androids Dream of Electric Sheep?” by Philip K. Dick. Many of the Easton Press editions I’m after are likely to cost around $60-100 (+pp) however this one, on which the movie BladeRunner was based, seems to be a minimum of $400 or thereabouts. Ouch. I still have the paperback dad gave me when the movie came out. I didn’t see the movie at the time but read the book instead. It would be nice to re-read it too. Today, I did at least buy the Easton Press edition of one of Dick’s other great works, The Man in the High Castle.

Posted in books | 2 Comments

virtually linux

These days I’m increasingly rusty techwise. After last week’s success writing a simple program in perl, I decided to try installing linux on my windows (8.1) laptop. Many years ago when I tried to doing this on an old XP box, it was a long and complicated process, involving BIOS changes, partitioning and other dark arts. I was always scared that I was going to do something wrong and make the machine entirely unworkable. I did manage to get an installation of Debian Linux running after a fashion. It often started with errors, usually with just the command line though on rare occasions it would try to launch the graphical interface (X), and mostly fail. Later, work provided me with a pre-built dual boot machine running ubuntu linux and XP.

Times have changed and dual booting is not the only way. Computers are powerful enough to run operating systems within the OS in virtual machines. These are much, much easier to install. I even found instructions for installing both a virtual machine and linux in 5 steps, easy steps they claimed. It was a wee bit harder than that with a couple of extra bits including a BIOS change but overall nothing too scary.

Following the steps which included sensible suggestions for each setup screen (not many setup screens either), the virtual box was straightforward to download and setup. However I’m running a 64 bit machine and it turns out my install of virtual box wouldn’t recognise 64 bit settings, only 32 bit. Turns out there’s a BIOS option for Intel’s Virtualisation and it was disabled by default. So I gritted my teeth, rebooted and went into the BIOS and enabled it. This ended up being easy and painless. Phew. Rebooted and now virtualbox recognised the 64 bit stuff.

Next step was to install linux itself. Having read around a bit I decided that I’d give Linux Mint a go, though I was fine with ubuntu previously. I downloaded the disc image, all 1.3Gb of it. I started up virtualbox, and created a new virtual machine and opened the disc image. This ended up being a *lot* quicker than the suggested 15 minutes, perhaps a minute or two on my machine (Sony vaio running on the i7 chipset) and started to load. Unfortunately, it didn’t quite make it all the way. Took a while to work out why and then after some googling, I came across a note that suggested increasing the memory. I had done this as part of setting up virtualbox initially but it looks like my settings hadn’t saved the first time. So I increased the memory and all good.

I now have linux mint running successfully in a window on my windows desktop. I can open a command line and use apt-get to install additional software. Amusingly, the first thing I installed was lynx, a text based web browser I used to use many years ago. This was installed from the command line by typing:

sudo apt-get install lynx

and voila:

mint2

Posted in tech | Leave a comment

a wee bit of code

A month or so ago, in anticipation of attending THATCamp, I thought I should finally start learning a new computer language and chose python. Alas, the reality was that I only got as far as writing the standard “hello world” program and no further. Last weekend’s time in Canberra has been percolating in the back of my mind and when a problem popped up this week, I thought “aha! I could write a script to do that”. I’ve long had a basic grasp of simple regular expressions for examining strings of text or numbers and used that to edit simple authentication scripts for a previous employer.

For the problem at hand, I needed to search for a particular barcode pattern in a spreadsheet and count them. As my regular expression experience was from perl, I’d see if I could learn enough perl to do the task. And I did. Though I cheated a little and used “grep” initially to pull out all the potential lines; basically I wanted to do a pattern match on a barcode for all lines that also included the word “Success”. So I used grep to pull out all the “Success” lines:

grep Success filename.csv >success.csv

and then wrote a perl script (csvbarcode.pl) to handle the pattern matching for the right barcode. I ran that script on my original file and, via the unix command line, piped it through a line counter:

perl bin/csvbarcode.pl | wc -l

to give me the total number of times it appeared. “wc” is an old unix tool that’s an acronym for Word Count. Adding the “-l” forces it to count lines instead of words. I’ve hardcoded the reference to “success.csv” into the perl script.

No doubt I could have done all of the steps via a perl script but my skill level isn’t there yet. I relied heavily on this tutorial and followed it through and modified it to handle the search for the barcode pattern.

Update: Had a couple of ideas overnight and improved the code this morning. It can now take a CSV file as an argument, and output the total number of successful barcodes. I no longer need to grep the file before, or run wc to count the lines afterward. The only thing it probably needs is a check to make sure the file itself is in the correct format.

Posted in tech | Leave a comment

mucking about

Yet another “…been awhile…” sort of post.

Currently at the National Library of Australia for THATCamp, which I’m hoping is a a way for me to reconnect with my techier side. I was last here for THATCamp in 2011 when I was getting into digital assets management. Having moved into eresource management, I haven’t had much of a chance to play at what I call the “command line” level.

I installed xampp on my laptop several months ago but haven’t had much of a chance to do anything beyond some simple html. This morning I participated in a session on dealing with bulk downloads from Trove’s newspaper archives and I spent most of it learning my way round my web server and dealing ultimately, with stuff that was mostly just pathname issues: working out where to store files, and where to reference them. Happily I got most of the way along and got an OAI harvester up and running. Still got a few errors to nut out but feel like I’ve made progress and starting to make use of the tools I have available.

Posted in conferences, ideas, tech | 1 Comment

fun with botero

Having discussed my interest in images in a book by Botero, I went ahead and ordered a copy online. It arrived last week. It’s a facsimile that is printed on demand. It’s a chunky tome, hardcover and well bound…well worth the $64 I paid for it. Unfortunately it doesn’t include any of the images. None whatsoever. Initially I thought there was a mixup with the book title and I ordered the wrong one.

It turns out that the version with the fantastical images was published in 1618, after Botero’s death whereas I’d bought the 1596 facsimile. However the woodcuts for the images would have been prepared during the 16th century, possibly for another work. The images were included in an “aggiunta” or appendix, that was attached to the fourth part. There were a total of 32 woodcuts included in the additional section. I found out most of the information via the notes for an edition that Horden House is selling…though I’m less keen to spend $32k on that copy.

Luckily I don’t have to, as I have at least found scanned versions of the Aggiunta online and available for download. I haven’t found a print-on-demand version though will investigate whether I can print this version. It turns out that the images themselves aren’t by Botero, but by Hans Burgkmair, a German woodcut printmaker of the 16th century. There was a book published in 1960 that included the Botero images with an introduction my Walter Oakeshott. However only 50 of those were produced and I haven’t found one for sale.

There is another work that features images by Burgkmair, “Triumph of Maxmilian I: 137 Woodcuts by Hans Burgkmair and Others“, and several copies of the 1965 work are available via abebooks. While I doubt very much that any are of the Botero images, reading a comment elsewhere, I get the impression that Burgkmair’s work is worth exploring further and so look forward to the arrival of yet another book.

Posted in books | Leave a comment