Page 9 of 28
here-documents in Perl
Here-documents are something that, once you know about them, you wonder how you ever got along without. I first learned about here-docs in Python many years ago, but didn’t know their proper name. In Python, you define a here document with three single or double quotes:
foo = """ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. """
One day, when I wanted to put some large blocks of text amongst code, I searched for a way to do this in Perl and found the syntax:
my $foo =<< "EOF"; Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. EOFNote the use of quotes for the string-terminating sentinel (EOF, in this case, though it can be anything), which affects how the sting is interpreted. Just like with other strings in Perl, double-quotes mean that variables and escapes will be interpreted whereas they are ignored in single-quoted strings.
Gas v. Diesel and Energy Content
Anyone who pays attention to the car world from an efficiency perspective has no doubt heard of the popularity that diesel engines have in Europe, but lack in the United States. Diesels post significantly better distance per volume of fuel (miles per gallon, furlongs per peck) than their gasoline counterparts. I’ve always wondered how much of this disparity can be accounted for by diesel fuel’s higher energy content. A quick search turned up some statistics (See table B-4) produced by Oak Ridge National Laboratory’s Center for Transportation Analysis which lists a gallon of diesel as containing 38.6 MJ per liter and gasoline as posesing 34.8 MJ/L. Not that big of a difference; gasoline has 90% the energy content of diesel.
How is this reflected in the mileage of a real car? Well, let’s look at a Volkswagen Jetta which, until recently in the US, could be had with a 1.8 liter gasoline engine or a 1.9 liter diesel. The gas engine gives 19 MPG city, 27 MPG highway for an EPA combined cycle of 22 MPG (VW Jetta 1.8L gas). The diesel gets 28 MPG city, 39 MPG highway and 32 MPG combined (VW Jetta 1.9L diesel). Working from the combined numbers, the diesel powerplant achieves 45% better mileage with fuel that contains just over 11% more energy content. Not a bad deal at all.
The next question is how this all works out for the environment. Historically, diesels have produced much more environmentally destructive exhaust containing more NOx and particulates. Recently, however, diesel fuel in the United States has been switched to an ultra-low sulfur variety which, in turn, allows for particulate emission control technologies to be employed, reducing the airborne matter released by diesel engines. Do the changes mean significantly cleaner emissions? I’m not sure, because the stats are difficult to find. Perhaps I’ll find them later.
A Failure of Logistics
[caption id=“attachment_326” align=“alignleft” width=“300” caption=“Wiper blades from Amazon”][/caption] My roommate ordered some wiper blades that Amazon had on sale. He did a single order and yet the blades came in two boxes, each easily large enough to fit both blades, even though the boxes shipped from the same warehouse.
Inventions
If I had this kind of cash, I would be of the same opinion:
Myhrvold’s friends, like Myhrvold, seemed to be of the opinion that there is no downside to having a CAT scanner, especially if you can get it for twenty-nine hundred dollars.
The New Yorker has a very interesting article by Malcolm Gladwell, author of The Tipping Point about Intellectual Ventures, a company that does nothing but think up inventions. They occasionally call sessions to which smart people are invited to talk and come up with patentable ideas, hand them to lawyers and then sell the patents.
Installing Proggy Fonts in Ubuntu
I don’t recall how I came across the free Proggy font family but I wanted to try them out on my Ubuntu workstation for use in Eclipse. After some searching, I figured out how to install TrueType (.ttf) fonts and the process is pretty straightforward. I downloaded and unpacked the fonts into ~/.fonts
, created a fonts.dir metadata file, added them to the font cache and when I restarted Eclipse, they were available.
~$ mkdir .fonts ~$ cd .fonts ~/.fonts$ wget http://www.proggyfonts.com/download/download_bridge.php?get=ProggyCl ean.ttf.zip ~/.fonts$ wget http://www.proggyfonts.com/download/download_bridge.php?get=ProggySq uare.ttf.zip ~/.fonts$ wget http://www.proggyfonts.com/download/download_bridge.php?get=ProggyS mall.ttf.zip ~/.fonts$ ttmkfdir -o fonts.dir ~/.fonts$ fc-cache -f -v
Off The Hook - 23 April 2008
This is the synopsis of Off The Hook that aired on 23 April 2008. The show runs live on WBAI at 7pm on Wednesdays. Call in at 212.209.2900 or send letters to oth@2600.com. The show is also available as a high-quality podcast.
In the studio: Emmanuel, Mike, Redbird, Redhackt, Not Kevin, Lexicon, Mojo from California, Al & Zach from North Carolina
On the phone: Bernie S in Philadelphia
There wasn’t a show last week because the show was pre-empted and there isn’t one next week; WBAI is having a Report to the Listener show during OTH’s time slot so listen in to hear about running a radio station.
Bernie S relates a Supreme Court decision concerning a man who was stopped for a traffic violation, arrested and, as part of the arrest, searched. The crux of the issue is that the reason for which the man was stopped was not an arrest able offense, thereby making such detainment illegal. As such, the state appeals court ruled that the pursuant search was also illegal a stance which was overturned by the United States Supreme Court, making the evidence collected during such a search admissible in court. In the case of Virginia v. Moore, the inventory search performed after the illegal arrest found illegal drugs and the evidence was used to charge Moore with crimes pursuant to those findings.
Another case concerning searches performed by border patrol for people entering the United States. The ruling made by the Ninth Circuit court states that border patrol agents need no suspicion to search persons entering the country at a border control station. Though the authority to search sans-probable cause has always been in place for border agents, the question of whether search laptops was also legal had been in question. Though it is still legal to encrypt data and refuse to divulge the encryption key, the concern of law enforcement officers simply seizing the device as evidence and delaying its return for months or years is brought up.
Bernie S brought up a very interesting combination of the above mentioned decisions wherein a law enforcement officer can illegally arrest you, such as in Virginia v. Moore, they may then search you and subsequently charge crimes based upon what the search finds.
The Australian government is exploring the introduction of laws allowing employers to read all of their employee’s company email in order to prevent cyber terrorism. In the United States, this is already the case since the owner of the network and computers, the employer, is the de-facto owner of all data upon them.
A council in England has employed laws meant to fight terrorism to put families under surveillance in order to ferret out fraudulent school placement applications.
As reported by Jane’s Police Review, London’s metropolitan police department is planning to equip all of their officers with microchips that will track their presence.
Israel says that Facebook is a threat to national security because soldiers and government employees post pictures of potentially classified material and equipment. Redhackt commiserates the desire to post pictures of oneself with interesting military hardware.
This weeks data loss comes from a New York Presbyterrian hospital that lost 40,000 records of patient names and social security numbers. Unsurprisingly, a spokeswoman fr the hospital says that there is nothing to show that the information has been misused.
Lexicon talks of the Not Our Concern Network Operations Center that will be in place at The Last Hope which he summarizes as a coat check for servers. Just reserve a spot and you can hook your box up to a big tube for the duration of the con. The con will also host a radio station for its entire duration. Named Radio Statler after the previous name of the hotel, the radio station is seeking people to help run it during the con weekend. If you want to help out with the con, or know about it, check out HOPE.net.
Auto-remove Old Items from The Trash in Mac OS X
Having a purgatory for files that are on their way to deletion, such as the trash can in Mac OS or the recycle bin in Windows, is a great idea, for even the most careful users occasionally delete something only to find that they later need it. Unfortunately, the two aforementioned implementations, as well as those in Gnome and KDE, only allow you to empty the trash all at once. Much more useful is to have a timeout where files that are sent to the trash are automatically removed after a period of time. I finally got around to implementing this myself in Mac OS by putting the following in my crontab:
0 5 * * * /usr/bin/find /Users//.Trash -mindepth 1 -maxdepth 1 -mtime +14 -exec rm -rf {} \;
Every day at 0500 any item more than 14 days old is delete from the trash can. To install it, read the linked article above or, if you know the command line, open a terminal, type crontab -e
, paste the above (substituting your username) and save the file.
Edit: In the comments, Matt mentioned Compost, a preference pane for OS X that provides the functionality I describe, but also the ability to limit the trash based upon size, and also manage the Trash on other volumes. Neat! It’s $20, but definitely makes this process easier and understandable if you aren’t a Unix person.
Multiple Variable Assignments with Perl's Binding Operator
I learned something new in the world of Perl regular expressions today when I came across this line:
my ($foo, $bar, $baz) = $string =~ /(.oo)(.*?r)(.*?z)/;
The operative side of the line, $string =~ /(.oo)(.*?r)(.*?z)/
is a normal Perl regex binding statement - apply the regular expression /(.oo)(.*?r)(.*?z)/
to $string
. What’s interesting is that the binding operator returns the things matched within the capturing parenthesis as an array, allowing you to assign them all at once, as demonstrated by the left hand side of that =
expression. The above statement does the same as the more verbose:
$string =~ /(.oo)(.*?r)(.*?z)/; my ($foo, $bar, $baz) = ($1, $2, $3);
Used in a scalar context along with the /g
modifier, this is an easy way to count count occurences:
my $count = $string =~ m/\./g;
Taqueria Pancho Villa
There’s a small chain of taquerÃas in the Bay Area called TaquerÃa Pancho Villa. At the San Mateo location this evening I noticed a plaque commemorating the revolutionary general. I took picture of it and translated it when I got home:
In tribute to Pancho Villa (Doroteo Arango [Arámbula, his full name]) To 119 years of his birth (San Juan River, Durango) And 74 years of his death (Parral, Chihuaua) San Mate, California 1997
Changing CPAN Mirrors
I wanted to change the mirrors that CPAN was set to use because it seemed that the first one on the list wasn’t responding. I figured there must be a way to do this from the CPAN command line and indeed, a quick Google search turned up a result. To do what I wanted, I first printed the current URL list, shifted off the offending host and then wrote the altered configuration to disk for next time
cpan> o conf urllist urllist ftp://archive.progeny.com/CPAN/ ftp://carroll.cac.psu.edu/pub/CPAN/ ftp://cpan.calvin.edu/pub/CPAN ftp://cpan.cse.msu.edu/ ftp://cpan.mirrors.redwire.net/pub/CPAN/ Type 'o conf' to view configuration edit options cpan> o conf urllist shift cpan> o conf urllist urllist ftp://carroll.cac.psu.edu/pub/CPAN/ ftp://cpan.calvin.edu/pub/CPAN ftp://cpan.cse.msu.edu/ ftp://cpan.mirrors.redwire.net/pub/CPAN/ Type 'o conf' to view configuration edit options cpan> o conf urllist commit
To completely reconfigure CPAN, you can use the command o conf init
.