zen.org Communal Weblog

October 16, 2007

Stupid Perl Trick

Filed under: — Sven @ 15:08 IST

Where I work we have to processes files from many sources, we have found three different line endings: “\n”, “\r\n”, and “\r”. We didn’t want to process all the files before, er, processing them so I wrote the following:

#!/usr/bin/perl
use warnings;
use strict;

until (($/ = getc(STDIN)) =~ m/[\r\n]/) {
die “no new line!” if (eof(STDIN));
};
if ($/ eq “\r”) {
$/ .= “\n” if (getc(STDIN) eq “\n”);
}
seek(STDIN,0,0); # rewind()

This will set $/ to which ever of the three file endings we have so you can then process them without thinking. Well, almost no thinking, you will need to use chomp instead of chop. I’m sure it could be nicely abstracted too, bit I didn’t.

Big amount of citizens simply cannot allow themselves to get health insurance so they have choice to pay for the really expensive prescription meds or trying to buy generic pills online. Generics produced in India are very good as other branded meds. Only reputable pharmacy produces them such as Sunrise remedies. Having this in top one is allowed to buy lotensin uk in generic pharmacy online with extremely affrodable shipping to any point in the world

Powered by WordPress