Saturday, February 01, 2014

Perl : gettting a list of values from a hash

This is trivial, but since I haven't seen it anywhere on the web, I thought it was worth sharing.

It's pretty common in Perl scripting to have a hash of values, and to want to get the values as a list sorted by the keys. (Actually, that's often why you created the hash in the first place.

Suppose you have a hash like so:

my %things = (
    ddd => 'Dennis',
    ttt => 'Tom',
    mmm => 'Mickey',
    aaa => 'Albert',

To get the values as a list sorted by the keys, the usual suggested method is this:

my @list;
foreach (sort keys %things) {
    push @list, $things{$_};
}

which is fine, and has the advantage of being totally obvious to anyone reading your code.

But there is another method which will do the same thing in one line:

my @list = map { "$things{$_}" } sort keys %things;

As I said, trivial, but worth documenting for others. And isn't every program just a collection of trivial elements?

Saturday, April 20, 2013

Efficient Document Management 101*

Repost of something I sent to staff at my place of work late last year. Still relevant.

An interesting survey was recently announced into staff printing, copying and fax. I didn't feel I should answer, because I would be an outlier in the results anyway, but this last question caught my eye:
What more could be done within the Division to encourage efficient document management?
There are a few things I can suggest, based on my own experience. I decided to go paperless around two years ago, and I have not printed or copied anything since. I think I was forced to send a fax, once, and found the process . . . quaint.

It does help that I have an iPad, which is great for keeping all your documents in an available space at all times. But I also happily read work related documents on my desktop screen or my laptop at home. I've never had a problem with that, and while I know many people say they don't like reading on the screen, I strongly suspect that's more about habit than anything else. And reading on the screen is obviously more efficient than the alternative "download attachment, send to printer, fetch from printer, read, file" process.

Since most documents are received by email now, let's look at that first:
  1. Email is a ready-made filing system in itself. There is no sane reason for printing and filing emails, because they'll always be available in your email folders. Ditch the filing cabinet -- it's not searchable!
  2. There's no sane reason to save attachments to disk, then move them somewhere else. They'll always be there, in your mailbox. See #1.
  3. If you're going to write a brief Word document and then attach it to an email, consider yourself an idiot. You're wasting time, and you're wasting the time of the recipients. Just write the thing in email. You can even format emails now, pretty much everything you need for standard documents is there in email.
  4. Remember to organise your email. If you keep everything in your Inbox, it will be harder to find things later, and eventually the Inbox will implode and create a black hole that sucks all your stuff into oblivion. Create some other folders according to what makes sense for you. Set up some filters so emails are "filed" automatically. Make the system do the work. That's what it's for.
So that's email.

What about document creation?
  1. As noted above, if your document is short and will be sent via email, then just send an email. Don't make extra work by using Word for something that will be just as effective as an email. Putting words into a Word document does not make them more important, valuable or intelligible.
  2. You may have "done a course" and be able to use all kinds of fancy pants stuff in Word. Don't. Just don't. Nobody cares how clever you are, and more importantly, if anyone else has to edit one of your documents, they may go insane trying to make it work, and then they'll hate you. Nobody needs more hate.
  3. Keep focus on the objective, which is to impart information. Ideally, send out documents as PDF, because that's what it's for. PDF = Portable Document Format. Then everybody is guaranteed to be able to read it. Even on a tablet.
  4. If you're creating a form for people to fill out and return, create a web form instead. Nobody wants to fill out your crappy form in the first place, so at least make it easy for them. And a web form can supply the intelligence lacking in people before they've had their coffee. (Like automagically calculating a number of hours from start and end dates.)
What about Fax?

You're kidding, right? In the 21st Century? No.

Copying?

No. But you could try …

Scanning?

Good idea. Because no matter how green you try to be, someone will inevitably send or give you bits of paper. When that happens, I just scan anything I need to keep, and bin anything else after I've read it. I have a scanner on my desk, but your office should have a copier that also scans. And if you have an iPad or a smart phone, that will also take a serviceable copy of any document. (Ideally, take a photo in front of the person who was crass enough to give you a piece of paper. Embarrassment is the best way to change behaviour.‡)


To summarise, the key to efficient document management is fewer documents. OK, so that's not going to happen, but we can take steps to ensure we spend less time managing the documents we do have. Ideally, documents should be electronic, because any time you have a piece of paper, you have to spend time doing stuff to manage it: filing it, hunting for it later, copying it for others, filing it again, ... So much simpler to keep an electronic copy.

____

* "101" is something Americans do to indicate a beginner's course in something. No-one in the rest of the world knows why.†

† OK, so we do know why. But it's a specifically American thing.

‡ That's actually a joke. It's not nice to embarrass people.

Friday, April 19, 2013

Marie Corelli

One thing to love about the web is the way one thing leads to another, to unexpectedly interesting things you had no intention of looking for (because you didn't know they existed) but which turn out to be at least as interesting as the place you started.

Thus it was that yesterday I was hunting for information on Olivia Howard Dunbar, a Victorian/Edwardian literary critic and writer of ghost stories, when I stumbled over another author of weird fiction, Marie Corelli, of whom I was totally ignorant. Extensive information on both was found (thank you Google) at Violet Books, which is a
domain for fans & collectors of literary ghost stories, Victorian science fiction, Yellow Nineties Decadence, H. Rider Haggard & haggardesque "Lost Race" novels, Marie Corelli & other occult romancers, Rafael Sabatini & Jeffery Farnol & all vintage swashbuckling historical romances, westerns, Yukon adventures, jungle tales, Sax Rohmer & all weird thrillers, classic detectives, vintage children's & young adult fantasies & series books, & all such things old, fictional, adventurous, & weird
-- in short, a brilliant resource for anyone interested in such books.

Anyway, Marie Corelli was, it transpires, in her day the most popular author in Britain, outselling the likes of Rider Haggard, Conan Doyle and H.G. Wells. How extraordinary then that her work seems to have been almost totally forgotten.

From what I have read, her work has a somewhat religious focus -- Wikipedia says

A recurring theme in Corelli's books is her attempt to reconcile Christianity with reincarnation, astral projection, and other mystical ideas.

But the description of her works places her in a wholly original category: The Master Christian concerns Jesus as a time-travelling street-urchin in London; The Sorrows of Satan has Satan as a misunderstood adventurer in the modern world; the hero of Ardath "travels back in time 7,000 years to a sweepingly fantastic world".

I can't wait to add these to my ebooks collection and start reading!

Saturday, May 05, 2012

George Herbert, squashed?

This has me intrigued. I went looking for a portrait of George Herbert, and found lots of versions (thanks, Google Images!) Most depict him as having a long, narrow face, but there's one -- just one -- which shows him looking more "normal". I found one site which presented both images, without comment, as here:

George Herbert George Herbert

Looking at these with my photographer's eye, I judge that the two images are clearly from the same source, and the one on the left -- the widely used one -- is clearly a distorted version. Wikipedia uses a fuller version of the left image, and there are six variations of the same at the National Portrait Gallery site. It's an engraving by Robert White, and the earliest version is from 1674, and obviously a frontispiece to his work:
George Herbert, by Robert White, 1674 - NPG  - © National Portrait Gallery, London

So, I'm intrigued. Did Herbert really look like that? Did someone think he looked strange and stretch the image horizontally to make him look "right"? Did the artist think a squished portrait was more artistic? We'll probably never know.

Monday, April 30, 2012

EMail : the social networking software that refused to die

I remember when Google+ was new, a number of people were, perhaps in an excess of excitement, suggesting it would be not just a Facebook killer, but a replacement for email. This was not a totally crazy idea, because at the functional level, there are broad similarities: email has contacts and mailing lists, G+ has circles; email has messages, G+ posts. So in theory, one could easily replace email with Google+, and in fact it could be a replacement for most of our day-to-day communication.

Alternatively, Facebook could be, indeed wants to be, a replacement for email, and they are approaching 1 billion users. Facebook provides a Message feature for private messaging  between individuals and groups. You can even have a Facebook email address so that people not on Facebook can send you a message, and vice-versa. [Unfortunately, FB Messages has a horrible interface with almost no features.]

So why, when almost nobody has a good word for email, does it persist?

The most obvious reason is ubiquity: just about anybody you need to contact has an email address, while only the smart people have joined G+. :) [At time of writing, the best guess is the membership is approaching 200 million.] Many email users are not (strange as it may sound) avid users of social media, so unlikely to be on either Facebook or G+.

A second, equally powerful reason is the if-it-ain't-broke argument. For all the I-hate-email angst you'll hear from any email user, and despite the relentless spam, as a means of communication, it works. It's well understood, and used correctly, it's reliable. 

And a third reason is, email is not yet ready to die. The concept is old, the protocols also, but the technology has not yet stagnated. EMail clients continue to improve, spam filters are doing an excellent job of eliminating most spam. For someone like me, who started with the Unix command line "mail" program, and progressed through elm, pine, Eudora, Netscape, Outlook, Thunderbird and now gmail, I've seen steady and continuous improvement in clients. And gmail continues to improve: gmail filters are brilliant, and are streets ahead of anything offered on the social networking platforms. As one who receives several hundred emails daily, who's work schedule is built around email, I don't think anything else could replace it at this time.

[Having said that, let me say I am equally happy receiving messages from people through G+, Twitter or even Facebook. But no way do I want to see all my work emails there.]

I think where we're at right now is this: that email has a place and a value which cannot be taken by anything else yet. But at the same time, for simple, uncomplicated casual communication between friends, social media beats it hands down. Horses for courses. And be happy that there are now more horses in the race.

[Ironically, perhaps, I'm writing this blog post in Gmail and sending it from there to Blogger. So sue me. It works.]
Um. .. OK. Just had a reminder email from Google that I have a Blogger account. I'd completely forgotten ... as you can see, the last post was 2002! Oh dear. Well, lot of water under the bridge since then.

I'm not sure I really want a blog anymore, since I tend to just throw things into Google+. But I'm not ready to discard this just yet.

In fact, one reason to keep this is that Google+ posts have some limitations: only one image per post, and limited formatting. So there may be value in keeping this for those times when I really want to go to town on a post.

Stay tuned!

Wednesday, November 20, 2002

OK -- getting the hang of this now. So here's where I'm at right now. I have four new servers I'm in the middle of installing/setting up -- Solaris 8 + Apache. Also, I'm trying to get up a Linux install on a new PC -- but the thing is TOO new and I'm having trouble with the video card, which XFree86 can't handle. Oh yeah, and there's a Library system to take care of too.

But what I'm really into is e-books. We have a collection of ebooks -- I'm calling them web books because they are all HTML and I like to emphasise that. Actually, the collection is all my own work -- at least the HTML is; the books' content is all someone else's work and the scanning & proofing was done by others (Project Gutenberg). But what fascinates me is the process of creating a usable web book from a (nearly unusable) plain text file. I have scripts to do much of this of course -- converting text into headings, converting ASCII quotes into nice curly-quotes, splitting the text into multiple pages, stuff like that. I wrote these texts, and over the several years I've been doing this, they've evolved into something quite sophisticated. But in addition there's always a lot of hand editing required -- both before, with the plain text, and after, to correct the things the script couldn't manage. Lots of work. Sometimes a web book takes me just 15 minutes to create. Other times, I can spend up to two hours on a web book. Most recently, I've been working on Charles Dickens, and his Sketches by Boz was a bugger.

But even so, the rewards are there -- I genuinely feel like I've created something, and find the results strangely pleasing. Occasionally I even read some of them!
How does one start? Is there a protocol for one's first blog entry? A form of introduction? Who cares. Apparently there are 750,000 blogs out there. Who'd going to read this one. Well, me for one. I'm a sys admin at a University Library, and this will (maybe) be useful to me in keeping track of where things are at. It will be useful too that the things is anonymous (I hope!) -- I will be free to say what I want without fear of (a) upsetting anyone; and (b) getting into trouble with my superiors.

That's it for now -- let's see what the thing looks like before proceeding. (This is in line with my personal philosophy of incremental implementation.)