The malpractice non-crisis

slaniel | Uncategorized | Wednesday, May 31st, 2006

 . . . is Kevin Drum’s headline. But again it’s worth pointing out: if we think we can win an ultimately political battle on the basis of facts, we are wrong. The “trial lawyers are suing our country out of existence” line has great resonance with the American public, which suggests that the conservatives who are mounting this attack have tapped into something fairly deep. Even if we have the facts on our side, it doesn’t matter. Yet liberals as a whole seem to have avoided learning about politics, on the theory that the truth will set them free.

Windows’ hidden features

slaniel | Uncategorized | Wednesday, May 31st, 2006

Call it a usability feature, but Microsoft’s desire to anticipate what you mean has some tradeoffs. Clippy the paperclip was the most innocuous, but a steady enough diet of this stuff leads to unanticipated security holes. Say what you will about UNIX’s impenetrability, but it’s built on a philosophy of leaving no mystery at all. It does what you tell it to, no more and no less. This may make it less usable, and it may rely on the users being more explicit than users can be expected to be. But it has its virtues.

(Via Bruce Schneier)

Random thoughts, May 29

slaniel | Anti-Intellectualism In American Life | Tuesday, May 30th, 2006

In no particular order, inspired by many hours of time spent with only my own head for company in various airports:

  1. Queso Valdeon — a blue cheese from Spain — is really unbelievably good. Thanks to Jamie for recommending it to me. Whole Foods has pretty bad cheese overall, but one thing they do well is blue cheese. And also Parmesan. And actually their raw-milk cheeses are good, so maybe the problem is less Whole Foods and more pasteurized cheese.

  2. I get the feeling that some large quantity of book, movie, and television consumption has more to do with distraction than with the consumption of interesting content. People need some way to relax their brains after a hard day at work, so they turn on the TV or pick up the latest potboiler, or watch a movie with a lot of explosions, and then they go on with the rest of their days. I suspect that this explains something like 75% of media purchases.

  3. More generally, I feel like there’s something kind of insulting to the human race, and insulting to God if you’re religious, about a large part of what Americans buy. I hate to be this much of a drama queen about it, but every time I look at a McDonald’s nowadays, I think, “Mankind is on this end of a few billion years of evolution; we are in some sense the pinnacle of a tower that started with proteins swimming in a sea of ammonia. We are the only species that’s capable — so far as anyone knows — of reflecting on its own place in the universe. And here we are, eating at McDonald’s.” It just doesn’t seem consistent with our station as a species. We’re the most intelligent and refined creatures ever to roam the planet, capable of producing astonishing works of beauty and grace, and this is really the best we can do?

  4. It’s also disheartening to me that so much of modern culture is meant to be consumed and disposed of within a few hours. I don’t know the history, so this may not be a new creation, but I suspect it is. If we look at the sales curve on most books, we probably find that there’s an initial spike and then a very quick drop-off; most books, I suspect, are actually out of print within a decade, though I’d like to see numbers on this. Likewise most movies: a movie like Notting Hill, for instance, probably isn’t expected to live much past its DVD release. It’s just not expected that people will think about this stuff for very long. I want very much — in my own life — to avoid the impermanence of mass culture. For one thing, I think taking a longer view of culture — reading books that have been around for centuries, watching movies that have been considered the peak of their craft for decades — reveals just how little new material there is in modern mass culture. Most of it was done better long ago.

Pardon the superciliousness here. I’m just frustrated by seeing nothing but Dan Brown books on my various flights, and hearing the continuous blare of the TV in LaGuardia. Modern mass culture is all about throwing images at people as quickly as possible, and giving them as little time to think about things as possible. I want very much to turn down the volume knob on mass culture in my own life, be more reflective, and gain a longer-term perspective on the world I live in. Mass culture is also all about destroying history as quickly as it’s created. I’m finding that reading books about American history (Hofstadter’s book was a miracle, which I’ve not adequately reviewed yet) is making it much easier to live in a world inhabited by George Bush; maybe, just maybe, the world has seen people like him before, and maybe we’re not so screwed. Maybe.

LaGuardia, you still suck

slaniel | Uncategorized | Tuesday, May 30th, 2006

I have decided that a direct flight is worth at least $75 more than a flight with connections, to me personally. LaGuardia is almost begging me to avoid flying through it; my U.S. Airways flight here from Burlington connected to a United Airlines flight to D.C., which meant that I had to go outside, then take a bus to another concourse, check in again, and go through security again. This has never happened to me at any other airport.

The formerly-major carriers — United, American, U.S. Air, and perhaps others — are dying, as well they should. I’ll be flying United to Oakland at the end of June, but thankfully that’s a direct flight; once they’re in the air, there’s not much they can do to mess it up. Before the flight leaves, though, they have so many options; their on-time percentage for the IAD-to-OAK, as I recall, is 60%. But as Adam Posh-Jessek (iTap’s name for him) noted helpfully, that means they only mess up 40% of the time!

Cop shows and fascism

slaniel | Uncategorized | Sunday, May 28th, 2006

Being back home — where my parents watch many crime dramas — reminds me of another hypothesis that I’ve been kicking around for a while: those dramas are objectively pro-fascist (or at least pro-authoritarian). It starts with the preface to Law and Order:

In the criminal justice system, the people are represented by two separate yet equally important groups: the police who investigate crime and the district attorneys who prosecute the offenders. These are their stories.

First of all, DAs prosecute innocent people quite often. So that’s a misstatement of fact. But the slogan also contains a sin of omission: the people are also represented by defense attorneys. The defense attorneys protect us from the government. Protecting us from the government is what the U.S. Bill of Rights is all about. Imagining that prosecution is the entirety of what protects the people is a classic misunderstanding of government, and a classic pro-authoritarian position.

Then there’s the continuously upstanding position of the cops. When the police break a rule, it turns out to be necessary so that they could protect us; when defense attorneys work within the system, and zealously defend their clients, it’s “getting off on a technicality.” This is a classic misrepresentation of what the Bill of Rights is about, and of what defense lawyers do.

Now take any one of these shows and punch up the above (e.g., 24, where Jack Bauer famously tortures people if he needs to). Then positively saturate the airwaves with variant after variant of the same formula (Law and Order: Special Victims Unit, Law and Order: Criminal Intent, Law and Order: Trial by Jury, Law and Order: Conviction, CSI, CSI: Miami, CSI: NY, CSI: Las Vegas). Then add in TV news, where “if it bleeds, it leads” is the formula, leading people to think that violent crime is much more prevalent than it is. (Law and Order: Bankruptcy Court has somewhat less punch.) And when people imagine the police who respond to these violent crimes, they envision someone like Jerry Orbach — rumpled, weary, but fundamentally good. They don’t imagine Justin Volpe, who sodomized Abner Louima with a broomstick handle while Louima was handcuffed in the Brooklyn 70th Precinct station; it doesn’t make as good copy.

Then add in the general societal hatred for defense attorneys, which has been stoked by corporate interests and by conservatives intent on pushing their law-and-order platform but which probably reflects some deeper American way of life. The deck is thoroughly stacked against the defenders of the Bill of Rights.

All told, it seems pretty clear to me that television pushes an authoritarian worldview. Someone who watches more TV than I do could probably make the argument more convincingly, but I’m pretty sure the general line of argument is correct.

Dear LaGuardia: I hate you

slaniel | Uncategorized | Sunday, May 28th, 2006

Things that suck:

  1. LaGuardia Airport.
  2. Chihuahuas on motherfucking airplanes.
  3. Chihuahuas generally; the fact that there was one on the seat behind me last night was proof of two judgment failures on the part of its owner: first that she bought one, second that she brought it on board the plane.
  4. Screaming babies. I don’t mean just crying babies; I have more or less grown used to them, such that I don’t even really pay attention to them anymore. But when the baby is screaming — just losing his or her shit — that is several orders of magnitude worse.
  5. Televisions. The U.S. has a hard time with silence: we seem to have a need for constant visual and auditory stimulation, and we watch television just as a way to fill up time. Normally I just find this annoying, but when combined with items 1 through 4 it is intolerable.

But now I am in Vermont, where there is silence aplenty if one wants it. And I sleep better here than I do anywhere else, because there is no noise outside. This is right and good.

Backing up your data

slaniel | Uncategorized | Saturday, May 27th, 2006

A writer of Joan Didion’s stature really ought to be backing up her data:

The play is not opening until next spring — March 29 at the Booth on 45th Street — and has not yet been finished. Ms. Didion is writing and rewriting the script; she is on the 10th draft since the time her computer crashed, she said, and there were who knows how many before that.

The thought that the next After Henry could disappear into the mists of Microsoft Word is more than a little vexing to me.

Extended childhood

slaniel | Uncategorized | Thursday, May 25th, 2006

I have this hypothesis that’s been banging around in my head for a while, that my generation is in some sense worse than our parents’ generation, because we delay adulthood longer than they did. I think a lot of maturity comes from getting married and having kids. Suddenly you have to think about someone else, and you suddenly can’t just do whatever you want to do.

Which isn’t to say that all married people are mature, or that all single people are immature. But I definitely notice a large difference between the married and single folks in my life (including myself, obviously). It rears its head in odd but predictable ways. For the most part, the people I know with kids are less abstract than the single folks: they have to get grounded quickly in the details of actually getting things done, and they can’t have their head in the clouds with speculation. Even married folks without kids give me funny and skeptical looks when I go off on one of my philosophical speculations; their looks say, “Stop fucking around and get some actual work done.”

Obviously there are caveats to this. Anyone who’s traveled on an urban subway system will note that not all parents are, shall we say, worthy of imitation. And more to the point, maybe it’s wrong to consider this brand of maturity positive; maybe it would be better for us as a society if we had fewer people bound by the constraints of parenthood.

For my part, though, I don’t think so. I do think there’s something detectably better about married people, and about people with kids.

Parallels

slaniel | Uncategorized | Tuesday, May 23rd, 2006

Zac Bir showed me his new Intel PowerBook, running Ubuntu and OS X using Parallels. Ubuntu ran at almost-native speed. Given that running OS X under Linux would probably be a severe pain in the butt, I think this more or less seals the deal: the next time I buy a laptop, it will probably be one of the Core Duo PowerBooks.

Todd Gitlin on pundits

slaniel | Anti-Intellectualism In American Life | Wednesday, May 17th, 2006

Speaking of AIIAL, I found a piece from the Chronicle of Higher Ed in which Todd Gitlin invoked it to attack pundits. I include it below the fold. It’s actually one of the more insightful things I’ve heard said about pundits. Gitlin is a well-known liberal historian who was, among other things, a member of the Students for a Democratic Society in the ‘60’s.

(more…)

Anti-Intellectualism in American Life

slaniel | Anti-Intellectualism In American Life | Tuesday, May 16th, 2006

I’m reading Richard Hofstadter’s Anti-Intellectualism In American Life right now. My first thing to note about it is that “Intellectualism” will hereby be abbreviated “i10ism” in keeping with i18n and l10n. Actually, maybe I’ll just call the whole book AIIAL. Yes. Yes I will. It’s my own goddamned blog, goddamnit.

Anyway, it’s great. Hofstadter tries to track down where anti-i10ism in American life comes from, and finds that its roots lie at least in the perennial conflict between religious scholarship and religious enthusiasm (sense 3). Here he is quoting Charles Chauncy’s Seasonable Thoughts on the State of Religion in New England:

Their depending on the Help of the SPIRIT as to despise Learning. To this it is owing, that so many speak slightly of our Schools and Colleges; discovering a Good-Will, were it in their Power, to rase them to their Foundations. To the same Cause it may be ascrib’d, that such Swarms of Exhorters have appear’d in the Land, and been admir’d and run after, though many of them could scarce speak common Sense  . . .  and to the same Cause still it must be attributed that so many Ministers preach, not only without Book, but without Study; and justify their doing so, lest, by previous Preparation, they should stint the Spirit.

To the exponent of a religion of the book, for whom a correct reading of the Bible was a vital concern, this was the ultimate heresy: that one who was possessed of the Spirit could, without study and without learning, interpret the word of God effectively enough to be an agent of the salvation of others. And here we have the nub of the difference between the awakeners and the spokesmen of establishments: whether it was more important to get a historically correct and rational understanding of the Book — and hence of the word of God — or to work up a proper emotion, a proper sense of inner conviction and relation to God.

As Hofstadter summarizes it in his introduction:

The case against intellect is founded upon a set of fictional and wholly abstract antagonisms. Intellect is pitted against feeling, on the ground that it is somehow inconsistent with warm emotion. It is pitted against character, because it is widely believed that intellect stands for mere cleverness, which transmutes easily into the sly or the diabolical. It is pitted against practicality, since theory is held to be opposed to practice, and the “purely” theoretical mind is so much disesteemed. It is pitted against democracy, since intellect is felt to be a form of distinction that defies egalitarianism. Once the validity of these antagonisms is accepted, then the case for intellect, and by extension for the intellectual, is lost. Who cares to risk sacrificing warmth of emotion, solidity of character, practical capacity, or democratic sentiment in order to pay deference to a type of man who at best is deemed to be merely clever and at worst may even be dangerous?

In a society where being a successful businessman is more or less the pinnacle of achievement, it makes some sense that intellectuals would be scorned. And at least since Adlai Stevenson, they have not been especially good at winning elections.

Hofstadter has thus far reserved his acid for Senator Joseph McCarthy:

What I believe is important, however, to anyone who hopes to understand the impulse behind American anti-intellectualism is that this grievance against intellectuals as ideologues goes far beyond any reproaches based on actual Communism or fellow-traveling  . . .  The truth is that the right-winger needs his Communists badly, and is pathetically reluctant to give them up. The real function of the Great Inquisition of the 1950’s was not anything so simply rational as to turn up spies or prevent espionage (for which the police agencies presumably are adequate) or even to expose actual Communists, but to discharge resentments and frustrations, to punish, to satisfy enmities whose roots lay elsewhere than in the Communist issue itself.  . . .  bullying was welcomed because it satisfied a craving for revenge and a desire to discredit the type of leadership the New Deal had made prominent.

Had the Great Inquisition been directed only against Communists, it would have tried to be more precise and discriminating in its search for them: in fact, its leading practitioners seemed to care little for the difference between a Communist and a unicorn.

When Hofstadter decides to turn a phrase, it turns on a dime. But even his workaday sentences are brisk, come to comforting closes, and pull you along to the next ones effortlessly. Better yet, I get the sense that this book is going to help me understand why liberals keep losing elections. And maybe put American history into some perspective will make the Bush administration seem less horrifying.

Pollan the blogger

slaniel | Uncategorized | Tuesday, May 16th, 2006

I really like Michael Pollan, and I really like that he has a blog, in which he writes about things like Wal-Mart’s sales of organic food (my cache). But I wish that every time a major-media company let one of its writers have a blog, that writer didn’t turn into a supercilious blog-mocker — à la “At the risk of sounding more equivocal than any self-respecting blogger is expected to sound  . . . ”. Can’t they just write what they want to write and not always act like they’re slumming it?

Archiving all the world’s books

slaniel | Uncategorized | Monday, May 15th, 2006

A little lunchtime math, prompted by a Times article about digitizing all the world’s books: one of the best ways to guarantee that these digital books survive longer than the library at Alexandria did is to ensure that there are many copies of the library spread across the globe. So my question is: what if every single computer on earth had a copy of the library? How much disk space would this take up on everyone’s machine?

Quick, conservative estimate: assume there are a billion books that we could digitize. Assume each book is 1,000 pages long. Assume each page contains 500 words, each 8 letters long. Assume further that each character needs 4 bytes to encode in something like UTF-8. All of these numbers are ridiculously conservative. Under these estimates, we’ll need 32 terabytes to capture just the text from all the world’s books. Assume we have to double that to capture all the images in all the world’s books at high resolution. That’s 64 terabytes in total. Assume conservatively that we could bzip those 32 terabytes of text at a 3:1 ratio, down to about 10 TB, and that the graphics are incompressible. So we’re down to 42 TB.

The Internet Archive has assembled the Petabox — where one petabyte is 1000 terabytes — for something like $2,000 per terabyte. Then again, it looks like the Petabox is supposed to be much more reliable than what we need here. If we assume that many, many computers around the world will be mirroring the library, we can deal with occasional — or even frequent — disk failures. So how cheaply could we buy 42 TB of disk?

Americans’ view of warrantless wiretapping

slaniel | Uncategorized | Sunday, May 14th, 2006

What we need more of is investigative journalism. Check out the New York Times’s article on the recent revelations about our government’s violations of FISA. A large fraction of the article is spent discussing Americans’ perception of the wiretapping program:

After the N.S.A.’s warrantless eavesdropping on domestic telephone calls was first disclosed in December, Bush administration figures strongly defended the effort as vital to the fight against terrorism. Opinion polls showed that their arguments carried some weight; Americans supported the surveillance program by a very narrow margin, with Republicans much more likely to back it and Democrats to be critical.

A new poll by Newsweek finds the public is becoming more critical of the N.S.A. surveillance program, although this could shift as the administration continues its defense.

Fifty-three percent of those surveyed by Newsweek said they believed that the N.S.A. program “goes too far in invading people’s privacy,” while 41 percent said they viewed it as a necessary tool against terrorism. No political breakdown of respondents was provided.

Is this as surreal to other people as it is to me? Americans believe or don’t believe something based on how the media choose to cover it. So this is a story reporting on Americans’ understanding of how well that story has been reported. Which means that a large fraction of this news story misses the whole point of its own existence.

Of course this happens all the time. Before anyone got around to covering the truth of the Swift Boat claims, the media were discussing the coverage that the story was getting. Charlatans win this way, because no one ever bothers to cover the facts of the story itself; we turn meta right away.

Why The North Won The Civil War and Conversations with Neil’s Brain

slaniel | Uncategorized | Saturday, May 13th, 2006

Just a couple quick notes on the books I’m reading.

I finished the just-barely-over-100-page Why The North Won The Civil War this morning on the way to Murky Coffee. It’s apparently the result of a small conference amongst six very well-known historians — among them David Herbert Donald (he of a magisterial Lincoln biography, appropriately entitled Lincoln), David M. Potter (posthumous 1977 Pulitzer Prize-winner for The Impending Crisis, 1841-1867, which is on its way to me with the help of a gift certificate from Sarah), and Henry Steele Commager, who with a name like that would have to be the “Dean of American Letters” even if he were illiterate.

WTNWTCW is a collection of six essays by the aforementioned gentlemen — all of them concise perhaps to a fault (do you know what the Erlanger loan was? Apparently all of the essayists did), and all of them quite well-written. They’re supplemented by a several-page-long annotated bibliography, which has led me to put Edward Channing’s History of the United States to 1865 and Allan Nevins’s Ordeal of the Union on my to-read list. (For that matter, Nevins wrote two Pulitzer Prize-winning biographies, one about Grover Cleveland and one about U.S. Grant. The prospect of interesting books about what appears to be the least interesting chunk of American history kind of awes me.) They give just enough of a taste of the subject to make me want more.

Probably the most fascinating aspects of the book, for me, were the diplomatic efforts to keep England and France from joining the side of the Confederacy (it sounds like it was quite scary for the Union for quite a while, and only Seward’s vigilance kept Europe away), and a comparison of Union generals with Confederate ones. For some reason it hadn’t occurred to me before that both Northern and Southern generals were taught at the same schools — were taught, in fact, at West Point. So most of them — with the exception of Grant and Sherman — had the same 18th-century view of war, as propounded by Antoine-Henri Jomini.

Indeed, the most interesting overall arc in the book — which may be well known to historians, but not to me — is that the Civil War is the closest thing that history has ever had to a study in causation. What would have happened had we changed this little thing? The Civil War is better documented than most any historical event, and both sides differ from each other in relatively minor ways, so the data are there for the picking.

As for Conversations with Neil’s Brain, the book that I’m working on right now, it is quite good in spite of Neil. Neil is a fictional character, an amalgam of several epileptic patients whom the book’s neurologist authors have met. The book switches between cafeteria chats with pre-operative Neil, and mid-operation electrical probes of Neil’s cortex. The neurologists take a tour through Neil’s brain, largely prompted by questions that Neil asks them.

The trouble with Neil is that he is a wholly non-believable character — e.g.,

Excitation and inhibition have a range of connotations, even Freudian ones, but to neurophysiologists they mean something close to addition and subtraction, or deposits and withdrawals. The neuron doesn’t subtract a molecule of inhibitory neurotransmitter from two molecules of excitatory neurotransmitter, however. The neuron avoids the “adding apples and oranges” problem by adding the positive and negative electrical currents that the neurotransmitters produce.

“Ah! Electricity is the currency of computation in the neuron?” /p>

Earlier the authors have told us that Neil is an MIT-trained engineer. To imagine that he doesn’t know this basic fact about neural computation is to imagine that he also doesn’t know about bits, and their electrical representation inside of computers. Which is unfathomable. Neil is just a device to take complicated ideas and make them palatable to the reader; he is not, in any strict sense, a character. To think that he fuses people whom the authors have met either says something quite terrible about the epileptics themselves, about the authors’ ability to relate to people, or about their memory for dialogue. In any case, Neil ought to disappear from the book: Conversations with a Brain would be much better.

Neil aside, the book is actually quite good. The authors take a breezy, yet detailed, walk around the brain, traveling from the lowest levels (neurons) all the way up to the highest-level questions, like: where does the executive function reside? Only halfway through the book, it’s already covered a lot of ground. And the authors are quite diligent about pointing out those areas where significant disagreement or ignorance remains.

Should you have any interest in the Civil War or the human brain (and who, at least, could possibly be uninterested in the latter?), these books will make very pleasant company.

Cunningmas?

slaniel | Uncategorized | Thursday, May 11th, 2006

Please tell me that the Cunningham scandal turns into something big and nasty. Please?

Abstraction

slaniel | Uncategorized | Wednesday, May 10th, 2006

I have a function to connect to a database and do some stuff with it. As it stands, that function is implemented through a shell out to mysql — i.e., the function looks like

sub doSomethingWithSQL { my $dbname = shift; my $username = shift; my $password = shift; mysql -u $username --password=$password $db_name -e "some query"; } 

If instead I had implemented this using the Perl DBI, I could have done

my $dbh = DBI->connect("DBI:mysql:database=$db;host=$host", $username, $password) or warn $DBI::errstr; 

and then the interface to doSomethingWithSQL() would be different:

sub doSomethingWithSQL { my $dbhandle = shift; my $sth = $db_handle->prepare(”some query”); $sth->execute; } 

Which is to say that the interface depends on the implementation. Which is a Classically Bad Thing.

So what’s the way to avoid changing the interface when the implementation changes here? To keep from changing the interface, I’d have to call in using a database handle as the argument. But I can’t shoehorn what the mysql command-line program needs into a DBI-style database handle.

I assume this pattern occurs often: interface depends upon implementation. Either that, or I need to call into doSomethingWithSQL() using every single argument that could ever be useful. But that’s obviously dumb.

So what’s the approach to get around this?

Editing a file in place inside another Perl script

slaniel | Uncategorized | Wednesday, May 10th, 2006

I often use Perl’s in-place editing as a speedier replacement for sed. I.e., I can do

perl -p -i -e 's/PATTERN1/PATTERN2/g' filename 

to replace every instance of PATTERN1 in filename with PATTERN2, and change filename on disk. The equivalent sed command would be

sed -i -e 's/PATTERN1/PATTERN2/g' filename 

But what if I have a Perl script where just one function is supposed to edit another file? I can call out inside that function to sed, or to another instance of perl -i, but both seem like hacks. I could write my own function that

  1. Reads a file
  2. Makes a substitution on every line
  3. Writes the substituted line out to a temp file
  4. Writes the temp file over the original file

but that seems to be reinventing the wheel. What’s the good way to do it?

Importing into MySQL via queries

slaniel | Uncategorized | Wednesday, May 10th, 2006

I’m used to exporting the contents of a MySQL database via

mysqldump -u user --password=foo databaseName > dumpfile 

and later on re-importing it via

mysql -u user --password=foo databaseName < dumpfile 

For various reasons, it would be helpful for me to know how to do the latter entirely with SQL queries. There’s the LOAD DATA INFILE query, but it seems aimed at a different task; it loads data into a single table.

Any idea how to get the command-line import into a SQL command?

Perl discovery of the day: handles have global scope

slaniel | Uncategorized | Wednesday, May 10th, 2006

I had a function like this just now:

sub doSomething { open(INFILE, '<$filename'); doSomeStuffWith(INFILE); } 

and I was curious whether I needed to add a close(INFILE) line at the end. For certain values of “need,” it turns out that I do. Here’s a little test script:

#!/usr/bin/perl use strict; use warnings; doSomething(); print OUTFILE "A line from the outer scope\n"; sub doSomething { open( OUTFILE, ">filename" ); print OUTFILE "Some stuff\n"; } 

If you run that, you’ll get two output lines in filename:

Some stuff A line from the outer scope 

whereas if you add a close(OUTFILE) to doSomething(), you’ll get this error:

print() on closed filehandle OUTFILE at /home/user/handletest.pl line 6. 

That’s kind of weird. I didn’t think that handles were totally different beasts than ordinary scalars. I would have expected them to get destroyed when we leave doSomething()’s scope.

The FileHandle module appears to fix this. Write a little program like so (call it handletest.pl for future reference):

#!/usr/bin/perl use strict; use warnings; use FileHandle; doSomething(); sub doSomething { my $fh = new FileHandle; $fh->open(">filename"); print $fh "Some stuff\n"; sleep 100; } 

then take a look at all the filehandles that handletest.pl has open — e.g., in /proc/[pid]/fd, where /code> is the process ID of handletest.pl. You’ll see something like so:

lrwx------ 1 user user 64 2006-05-09 16:32 0 -> /dev/pts/0 lrwx------ 1 user user 64 2006-05-09 16:32 1 -> /dev/pts/0 lrwx------ 1 user user 64 2006-05-09 16:32 2 -> /dev/pts/0 l-wx------ 1 user user 64 2006-05-09 16:32 3 -> /home/user/filename 

which tells you that, apart from the ordinary stdin, stdout, and stderr, handle_test.pl has open a handle to /home/user/filename. This is what you’d expect. If you instead move that sleep 100 line out of doSomething() and look in the same /proc area, you’ll see only the standard filehandles — nothing for filename.

Which is to say: FileHandle does what you’d want. FIN.

P.S.: The Perl FAQ has something to say about this.

Next Page »

Bad Behavior has blocked 845 access attempts in the last 7 days.