12-inch pianist

You don't always get what you expect.

Perl tip - Reading a file into a string

I recently needed to check to see if a file had a particular tag in it before continuing, but I didn’t want to have to read it line by line to find out.

To my astonishment, there is no simple way to read a whole file into a string in Perl. The simple solution would be to use File::Slurp, but since the script will be running in a closed system I could only use default libraries. Also, because it’s Perl, I wanted to do it in a single line to maintain maximum incomprehensibility.

After a bit of tooling around I came up with this:

#!/usr/bin/perl -w

use strict;
use warnings;

# Check the file to ensure it contains the tag before continuing
my $FILE = $ARGV[0] or die $!;
die "File is missing required TIMESTAMP tag.\n" unless do { local $/; local @ARGV = $FILE; <> } =~ /TIMESTAMP/;
...

Essentially, what’s going on here is that I’m unsetting ‘$/’, the Input Record Separator, to make <> give the whole file at once.

Props to Stack Overflow for pointing me in the right direction.

Posted 3 hours ago
Loading mentions Retweet

Syntax highlighting comes to Posterous

Here is some Python code!

 1 # sample Python code snippet
 2 # bonus points if you know what this is
 3 from __future__ import generators
 4 
 5 def firstn(g, n):
 6     for i in range(n):
 7         yield g.next()
 8 
 9 def intsfrom(i):
10     while 1:
11         yield i
12         i = i + 1
13 
14 def exclude_multiples(n, ints):
15     for i in ints:
16         if (i % n): yield i
17 
18 def sieve(ints):
19     while 1:
20         prime = ints.next()
21         yield prime
22         ints = exclude_multiples(prime, ints)
23 
24 if __name__ == '__main__':
25     for i in firstn(sieve(intsfrom(2)), 400):
26     print i
Posted 2 months ago
Loading mentions Retweet

Crab People...

Q: Who is the best wife? A: J.J. is the best wife.

Posted 2 months ago
Loading mentions Retweet

I'm sorry, I thought you was corn.

Posted 3 months ago
Loading mentions Retweet

The kitten & dog have been replaced in my nightmares.

Posted 3 months ago
Loading mentions Retweet

Next in the series of adorable animals from my nightmares

As a bonus, keep on the lookout for a secret goatse around ~1:35.

Posted 3 months ago
Loading mentions Retweet

This dog has walked right into my nightmares...

Posted 3 months ago
Loading mentions Retweet

Hey, I uploaded my first video to YouTube!

It features my cousin Miles decorating Easter Eggs--OH BOY!

Posted 3 months ago
Loading mentions Retweet

Bobby Lots Steps Down

I always remember him being a pretty cool dude. I wonder who the new prez will be?

---------- Forwarded message ----------
From: Office of the LMU President <thepresident@lmu.edu>
Date: Mon, Mar 1, 2010 at 5:04 PM
Subject: Message From the LMU President


March 1, 2010

Message From the President
March 1, 2010

Dear LMU Community,

At today's quarterly meeting of the Board of Trustees, I submitted my resignation as LMU's 14th president, effective at the end of this academic year.  Our board has accepted my resignation, and a search will begin soon for my successor.  Executive Vice President and Provost David W. Burcham will become interim president and will serve during the search for a new president.  Dave has a long and distinguished history with LMU, first as a student, having received his J.D. from Loyola Law School, as a faculty member when he returned in 1991 and as an administrator when he was appointed the 15th dean of the law school in 2000.  He took on the role of provost in 2008.  Dave is well-prepared to lead LMU until a new president is selected.

Two (not three!) considerations have motivated my decision.  One is my health.  The recovery from my back operation has been slow and has affected my ability, because of my schedule, to do the physical activity and exercise advised and, more importantly, to do my job to the fullest.  I plan to take a sabbatical and that should allow me time to do what is required to return to full health, or at least to as much health as my age allows!

The other consideration is deeper.  It is what I might call "the rule of ten."  Ten years in these kinds of jobs is usually enough and after that both the institution and the person benefit from change.  At least that is true of me.  I served as Dean of Georgetown College for ten years and had originally intended to serve in this job for ten as well.  I am now in my eleventh.  I subsequently thought that it made sense, given the extension of the campaign until October, 2011 and the centennial celebration in 2012, to continue until then.  But our fundraising professionals are superb, and both Dave and, I am sure, my successor will be more than able to work with them to meet our ambitious goal of $380 million.

Moreover, the dedication of the William H. Hannon Library affected me deeply.  John Ruskin "proposed that we seek two things of our buildings.  We want them to shelter us, and we want them to speak to us."  The library said powerfully to me that my work at LMU was basically complete, that I had accomplished what I came here to do.

 Now, finally, we get to what I most want to say (I guess I do have three points after all)!  As Sebastian says to Antonio in "Twelfth Night," "I can no other answer make, but, thanks, and thanks, and ever thanks."  Thank you all, faculty, staff, students and alumni, so much for making my LMU years so wonderful and fulfilling.  To have worked and played with you in caring for this great university and the larger worlds it serves has been a grace indeed.  My feelings these days are best expressed by Saint Exupéry:

Old friends cannot be created out of hand. Nothing can match the treasure of common memories, of trials endured together, of quarrels and reconciliations and generous emotions.

May God bless LMU now and for centuries to come.


Sincerely,
 
Robert B. Lawton, S.J.


1 LMU Drive, Los Angeles, CA 90045-2659 Phone: 310.338.3065 | http://alumni.lmu.edu

Loyola Marymount University
1 LMU Drive
Los Angeles CA 90045
www.lmu.edu

Posted 4 months ago
Loading mentions Retweet

I am doing it wrong.

They're talking about finding meaning in temporality, right?

Posted 5 months ago
Loading mentions Retweet