Perl and Multiple Line Ending Characters

January 6th, 2007

Perl uses \n (the linefeed) as its default end of line character (record separator). You can change this with -0 option on the command line to be \r (carriage return), \r\n (carriage return linefeed pair) or something else. For example, this command sets the record separator to \r before replacing every occurence of the string foo with the string bar:

$ perl –pi -e -00d ‘s/foo/bar/g’ test.html

However my files are a weird mix of Unix, Mac, and Windows conventions. A few files may even use several line ending conventions in one file. Most modern text editors can autodetect and deal with this without any problem, as can XML parsers. However as near as I can figure, Perl cannot. It expects me to know in advance what kind of file I’m feeding it.

Is there any simple way around this? There’s more than one way to do it, but is there more than one $/?

All Dollars are Equal: A Common Economic Fallacy

January 4th, 2007

Here’s an example of an all-too common fallacy in assessing the rationality of economic actors. It comes from Daniel Kahneman and Jonathan Renshon in Foreign Policy in an otherwise interesting article:

Imagine, for example, the choice between:

Option A: A sure loss of $890

Option B: A 90 percent chance to lose $1,000 and a 10 percent chance to lose nothing.

In this situation, a large majority of decision makers will prefer the gamble in Option B, even though the other choice is statistically superior. People prefer to avoid a certain loss in favor of a potential loss, even if they risk losing significantly more.

Kahneman and Renshon believe Option A to be the rational choice, but in fact Option B should be preferred by most people, most of the time. Do you see why?
Read the rest of this entry »

Security by Stupidity

December 30th, 2006

Yesterday I went through the airport security lines for the second time since the new no liquids, no gels rules were imposed; and I learned something new. Not only can you go through with four 3.5 oz bottles of liquid but not one 12 ounce bottle. It doesn’t actually matter how much liquid is in the bottle, only what it says on the side of the bottle.

You can walk right through with six ounces of liquid in a bottle that’s labeled as three ounces, but Lord help you if you try to go through with a half full, four ounce bottle. Furthermore you can still buy 20oz bottles of water and Diet Coke on the other side of the checkpoint so someone is able to get cases of liquids through. Yeah, this makes so much sense.

A Real Christmas Bird Count in Metairie

December 28th, 2006

Christmas morning I decided to do a little unofficial bird counting before most of my family woke up for the usual festivities. I didn’t go anywhere special, just made a loop through my Old Metairie neighborhood. My family swears there’s nothing to see out there, just House Sparrows, Blue Jays, and Mockingbirds; but they really aren’t paying attention. There’s a lot more when you look.

I have a regular three mile circle route that takes me up Homestead Ave. to Metairie Playground, around the playground, up the railroad tracks to the 17th Street Canal, down the Canal to where it meets the Canal Street canal; down Canal Street to the I-10 service road, and down the service road back to Homestead Ave. It takes about two hours to follow, and takes me through as varied a habitat as you can expect in suburbia.

One thing that always surprises me when I do this is how few other people are doing it too. Nobody in this town walks anywhere. Getting from the far end of the Lakeside Shopping Center parking lot to Dillard’s is considered a major hike. Yesterday I passed two joggers and no one else on the entire three-mile, two hour excursion. Yes, it was early on Christmas morning, but that’s about par for the course even on a beautiful Spring afternoon.

My goal was to find at least one species I had not previously seen in the neighborhood. That proved a little too unambitious since in the first half block between my parents’ house and Homer Street I found two: Ring-billed Gull and Yellow-rumped Warbler. I also ticked off some of the usuals: Blue Jay, Northern Cardinal, and Northern Mockingbird.
Read the rest of this entry »

#365: White-winged Dove

December 28th, 2006

Abita Amber packs a little more of a kick than I remembered, so yesterday after a beer and cheese fries lunch at Cooter Browns I decided to take a stroll around Audubon Park rather driving straight home. Lucky I did because I finally found five White-winged Doves flitting around in one of the Live Oaks near the Audubon Institute.

White-winged Dove, Audubon Park

I’d been looking for these repeatedly in the Uptown streets without any success, despite fairly precise directions as to where they were likely to be found. This is probably the last life bird I’ll pick up this trip and likely this year, unless something really weird shows up in Prospect Park this weekend.
Read the rest of this entry »

#364: Black-bellied Whistling Duck

December 27th, 2006

Yesterday I took a very brief jaunt to Audubon Park where I was informed Black-bellied Whisting Ducks could be easily found. I didn’t find the 1000+ flock I was promised (Maybe they’d flown off to feed somewhere else, or I didn’t hit the right pond?) but I did find these seven:

Black-bellied Whistling Ducks
Read the rest of this entry »

Currently Reading