Archive

Archive for March, 2010

Perl

March 27th, 2010 subogero Comments off

I love Perl. The beautiful friendship started blossoming recently. I remember a few years ago, before I got infected with Unix, I was always scared to death when confronted with Perl. But after half a year of meddling with Bash, GNU coreutils and regular expressions, I happened to look into an occasional Camel-smelling script and, much to my surprise, I was literally shocked by its beauty. Let me list my personal highlights.

Perl is like human languages.

open(FILE, "< $filename") or die "$filename could not be opened for reading.";

In Perl, there are many ways to express yourself to stress different things, like in human languages. Not like in German.

if ($foo) { print "Foo!"; }
print "Foo!" if ($foo);
print "Foo!" unless (!$foo);

Perl is very terse, like good slang.

Ever heard of Perl Golf?

Perl comes with batteries included.

With everything from Bash and coreutils, without using any extra modules. In the little Hungarian calendar below, I open a filehandle for a pipe from another program, I use the command line arguments, I do string substitutions.

#!/usr/bin/perl
open CAL, "cal -m @ARGV |";
while (<CAL>) {
  s/January/ Január/;
  # translations for other months and days ...
  print;
}
close CAL;

I forget, where did I hear this “batteries included” last time?

Default variable $_, especially when it’s not even written. Just like ogc (or vice versa).

Look at the code above. Guess what the s/// substitution is working on? Guess what is printed? Exactly. The hidden $_ variable, the result of the previous operation.

Variable substitution within regular expressions.

In my first ever Perl-script I came across some substitution problem where a part of the pattern to change was stored in a variable. I thought: How nice it would be to be able to put the variable into the regexp. I googled it. Of course it works.

$foo =~ s/(^.* )$variable$/$1$bar/;

And don’t tell me it’s unreadable…

Perl is available for Windows.

At the slightly brain-damaged company I work for, I can write small programs for slightly brain-damaged users. They don’t have to install Cygwin to run them, but Perl gives me the full arsenal of Unix.

The Perl style guide.

Compactness. Readability. No bullshit.

The Camel book.

I keep laughing out loud reading it.

Larry Wall is a Bible guy.

Remember, Perl comes from a linguist who originally wanted to translate the Bible into exotic languages.

Larry Wall is always right.

Even when he is not.

Categories: Uncategorized Tags: , ,

Jaunty Keyboard Layout Settings 2

March 18th, 2010 subogero Comments off

Finally. I’ve picked up my US keyboard for the ASUS UL20A today. Installation was surprisingly easy, with no warranty-void-if-removed stickers anywhere. Time to play again with keyboard settings. Default layout became US International (with dead keys). I kept Hungarian (qwerty) as well for the occasional őŐűŰ. And now to the most interesting part, the Layout Options.

Ctrl Key Position, Make CapsLock an additional Ctrl.
Hurraaaaah!!!! The bloody CapsLock is eliminated at last!

Key(s) to Change Layout, Both Shift keys together.
A combination of keys far away from each other, never normally used together.

Use keyboard LED to show alternative layout. CapsLock.
Of course. As the bastard is dead, I can use its LED to indicate if the Hungarian layout is active.

This incredible abundance of keyboard settings is amazing. A good reason alone to choose Linux over Windows.

Old Stuff Forever

March 3rd, 2010 gergo Comments off

I just read a quite interesting article full with pictures, that blow my mind. What can take 5 or 10 second to load a page. That was the last kick to try lynx.
First of all I checked it, maybe I already have it, so just type lynx, and I got:

The program ‘lynx’ can be found in the following packages:
* lynx-cur
* lynx-cur-wrapper
Try: sudo apt-get install
lynx: command not found

That’s the spirit that I like, respect for the parents. So after 5 minutes I have been a happy user of lynx.
The first test was the article itself:

$ lynx http://belsoseg.blog.hu/2010/02/28/hogyan_nem_vettem_svedorszagbol_ven_mercit

and I got my first suprise:

belsoseg.blog.hu cookie: PHPSESSIDv2=3fc04fea2eef22ad919e54d9b45e3066 Allow? (Y/N/Always/neVer)

then just put a v and you are out of the watching eyes of the big brother, free like at the dawn of the net. After it an another cookie try to watch my activity but I just laugh in her face.

Of course there are dark sides of lynx: in case of Hungarian text the accents can cause some ugly stuff. But this is my own problem to stick to my mother language. So guys if want to break down your monitor because of slow internet I can say there are other options.

Categories: Uncategorized Tags: ,