hi,
these days I was encountering a problem, when I was going through 2 veeeeeeery big hashes to find out which of them have similar keys (not really same keys, just slightly different). I thought, that the easiest way would be to go through both hashes in 2 for-loops and check them out one by one. Unfortunately, this approach took about 2 minutes to go through (2 minutes seem like an eternity if you are staring at a terminal).
My first approach looked like this:
for my $a (keys %b) {
for my $c (keys %d) {
if ($c =~ m/^$a.+$/) {
print "bingo!\n";
}
}
}
You see, the keys in the second hash (%d) always look like the keys in the first hash (%b) with the only difference, that they contain the key plus some other stuff. So if $a looks like “abc”, $c looks like “abc123″. Now, if you have 2 hashes with – let’s say – 5000 keys and values, you can easily calculate how long this could take…. (5000 x 5000 = 25.000.000) … as I already said: it takes FOREVER!
Now, after some searching around I found a very nice solution on the Linux and Unix Forums from a guy called “pludi”. He recommended a grep-approach. Here is now my remodelled version:
for my $a (keys %b) {
for my $c (grep { /^$a.+$/ } keys %d) {
print "bingo!\n";
}
}
Voila. Instead of taking 2 minutes, the loop now runs through in 15 seconds.
I love Perl
just started playing with my new motorola milestone with android 2.1. 
I had no idea how much fun it is to write perl-programs for this nice little device. I use the ASE (android scripting environment) which also supports python, lua, ruby …
You can get it on their website.
I guess I will write some programs soon to see what’s possible. The only thing that sucks on the milestone is, that the dollar sign is only available via touchpad. That’s REALLY annoying. :/
ok, today I finished my work at the fancy little script I mentioned yesterday. You can download it now here. Because wordpress for some reason doesn’t allow me to upload files without a filename-extension (grrr) it now has a txt-ending. please just ignore the extension …..
you call the script like this:
$ ./oebbquery "Innsbruck Hbf" "Wörgl Hbf"
Connections from Innsbruck Hbf to Wörgl Hbf:
Departure Arrival Duration Changes Train(s)
15:13 15:59 0:46 0 rex
15:28 16:24 0:56 0 s
15:54 16:28 0:34 0 oec
Please be sure to use the correct names of the stations. for example: “wörgl” doesn’t work, but “Wörgl Hbf” works. You have to use the names provided by the oebb-website.
the output looks now like this:

have fun!
hi guys,
I just spent 2 hours on a little project here. With this little script written in Perl by using LWP you now have the possibility to view train-connections from A to B in your terminal. You can then use this output to process it with conky or just any application you want. Here is a screenshot:

As you can see, i used it to display it with conky by executing it once every 600 seconds.
As soon as I have cleaned up the code to make it easier to read, you can download it here.
I can’t tell you how often I see scripts and programs which contain a huge amount of echo, print or whatever calls to produce output. It is ok if there are one or two lines to print out, but it becomes inefficient when used explicitly. In shell-scripts and Perl for example you could use so-called Here-Documents. Never heard of them? Well, here some examples:
example: bash
#!/bin/bash
# usage text
usage() {
echo ""
echo "This is the usage of blabla"
echo "Parameters:"
echo " -f ... Parameter 1 blabla"
echo " -g ... Parameter 2 blablubb"
echo ""
}
Well, here you can see that there are a lot of echo-calls (often there are MUCH more … :-/). Now, we learn about an exciting new way to shorten this. We use “cat”:
example: bash better
#!/bin/bash
# usage text
usage() {
cat << EOUSAGE
This is the usage of blabla
Parameters:
-f ... Parameter 1 blabla
-g ... Parameter 2 blablubb
EOUSAGE
}
So, instead of using tons of calls, just do it with one “cat”. Maybe it seems a bit pedantic of me, but this example makes more sense if you encounter more text (like HTML-output) which is printed out to a document with thousands of “echo”-s.
You can do this in Perl similarly:
#!/usr/bin/perl
# usage text
sub usage() {
print <<"EOUSAGE";
This is the usage of blabla
Parameters:
-f ... Parameter 1 blabla
-g ... Parameter 2 blablubb
EOUSAGE
}
or in Ruby:
#!/usr/bin/ruby
# usage text
def usage
print <<EOUSAGE
This is the usage of blabla
Parameters:
-f ... Parameter 1 blabla
-g ... Parameter 2 blablubb
EOUSAGE
end
I guess you can do something like that or similarly in nearly every language. So PLEASE, if you have much text to display in your scripts, use Here-Documents.
#### UPDATE #####
To have a look at the project:
click me
###############
hi guys,
I decided to register an account on github to share some of my coding projects with the world. By now I only uploaded huntersim so far but some others will follow soon. If you want to help me by commenting or patching it, feel free to do so. Get an account at github.com and tell me you account name by mail. I could then add you to the collaborators and you can submit your changes directly. If you just want to take a look or run the program you can of course just clone the repository without registration.
The public clone URL is: git://github.com/ap0calypse/huntersim.git
You can clone the repository with the following command:
git clone git://github.com/ap0calypse/huntersim.git
So, if you want to contribute to the project (or fork it, whatever) tell me your username and I add you to the collaborators. You should have some git knowledge. But don’t be scared. You can’t destroy anything
hi guys,
some days ago I decided to write a little simulation in Perl. Well, … here is the result (huntersim-0.1). The package contains a README where everything should be explained.
Have FUN!
UPDATE:
Because people want to see pics:

UPDATE:
##############
I now rewrote the script a little bit to use a private MAC-area because of problems when generating some MAC-addresses. Please use this version if you want to use it …
##############
hi guys,
yesterday I told you how to change your MAC address. Because I’m unbelievably lazy I decided to write a little helper-script to do this automatically. This script generates a random MAC address and brings the interface up with it.
here it is: change-mac
#!/usr/bin/perl
use strict;
# name: change-mac
# author: ap0calypse (ap0calypse@agitatio.org)
# purpose: helper script for bringing an interface down
# and up again with a random MAC-address
# date: 2009-04-15
# replace this with your wlan-interface
my $interface = "wlan0";
my @val_mac = (0 .. 9, "A" .. "F");
my $rand_mac = "AC:DE:48:";
for (1 .. 6) {
$rand_mac .= $val_mac[rand(@val_mac)];
if ( ($_ % 2 == 0) && $_ != 6) {
$rand_mac .= ":";
}
}
system("ifconfig $interface down");
system("ifconfig $interface hw ether $rand_mac");
system("ifconfig $interface up");
good morning 
As I wrote in my last article I wrote a small programm to display a 5×9 matrix of letters like the commandline tool banner does. Of course, my version isn’t that powerful, but it works. my_banner doesn’t do line-breaks, so if the sentence is too long you’ll see simply nothing very useful
.
Here an example:
echo "ABCDEFGHIJKL" | perl my_banner
### #### #### ### ##### ##### #### # # ### ### # # #
# # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # #
# # #### # # # ### ### # ##### # # ## #
##### # # # # # # # # ## # # # # # # #
# # # # # # # # # # # # # # # # # # #
# # #### #### ### ##### # #### # # ### # # # #####
and another one:
echo 'This is a test' | perl my_banner
##### # # #
# # # # ### ###
# #### #### #### #### # ### #### #
# # # ## # ## # # # # # # # #
# # # # ### # ### # # # ##### ### #
# # # # # # # # # # # # #
# # # # #### # #### #### ## #### #### ##
Here is the source: my_banner
You may ask yourself how it works? Well, I did it this way:
I figured out, that an ‘A’ for example would look like this in a 5×9 matrix:
### 01110 = 14
# # 10001 = 17
# # 10001 = 17
# # 10001 = 17
##### 11111 = 31
# # 10001 = 17
# # 10001 = 17
Well after I figured this out, I created an array inside of a hash for every letter from a-z A-Z and some special characters.
my %led_letters = (
'A' => [qw( 14 17 17 17 31 17 17 0 0 )],
....
'g' => [qw( 0 0 15 17 17 17 15 1 30 )],
....
);
The rest was easy after that. Maybe someone wants to expand it. Enjoy!
I’m currently thinking about writing my own blog-software. Yes, I know that there are hundreds of projects out there and some of them (like wordpress, which I currently use) are really good and have huge communities. But that’s not the point.
The reason why I’d like to do that is that wordpress is too feature-rich, too bloated for me. I don’t need 90 % of the functions it has to offer. All I want and need is a simple listing of stuff I’m currently thinking about or working at. Of course, there should be a nice interface for me to insert new articles, but I actually don’t need the ‘comment’-function. If someone wants to tell me something, he could drop me a line via e-mail too …
So, that’s why I’m thinking about creating my own blogware. It would be a nice exercise anyway. If I really complete this project I guess I’ll publish it under an open source license for anyone who wants to use or modify it for his/her needs.