Sonntag, 26. Mai 2013

Impressions from the Linuxtag 2013

This year we had a project booth from Rex on the Linuxtag. I have to say that i liked it very much and i will try to organize a project booth next year, too. Perhaps in conjunction with a Rex workshop.

Because the project hadn't done a lot of publicity yet, this was the projects first booth on such a exhibition/conference. And i want to thank inovex to sponsor the banner, the flyers, t-shirts and the hotel for the project members.

We had a lot of interesting talks about configuration- and deploymanagement the pros and cons of a lot of other tools in this category and of course about Rex.

There where also some nice ideas how to extend Rex to make it easier for administrators (who don't know perl) to work with or to better scale to a large server cluster. I'm going to add some of these ideas in one of the next releases.

Most people didn't know Rex at all and asked to explain what Rex does in a few sentences. These conversations always ended up in a longer conversation (10-20 minutes, or even longer)

One interessing (or funny) thing i noticed during these conversation was, that american people (or people working for american companies) always asked about scalability (that was mostly the first question by them) and european people wanted to know how it works or how they can extend it (only a few asked about scalability).

This year i hadn't had the time to visit some talks because i was all the time on the booth. But from the things i've heard there was some nice talks.

So for the next time i have to plan a bit more better so that i can go to some talks, too :-)

Sonntag, 17. März 2013

Perl IO with IO::All

Working with Files and Directories in Perl Programming is not really a big deal. But there is a  module that ease this in a cool way.

If you want to do IO operations in Perl i advice you to take a look at IO::All.

File Operations

Opening a file in the traditional way is done with the open() function and than you can iterate over the lines.
my @lines;
open my $fh, "<", "the-file";
@lines = <$fh>; 
close $fh;
With IO::All you can simplify this to one line
my @lines = io("the-file")->getlines;
If you want to load a complete file into a string you have to do the following without IO::All:
my $content;
open my $fh, "<", "the-file";
    local $/;
    $content = <$fh>; 
close $fh;
Compared to IO::All it looks a bit too much:
my $content = io("the-file")->all;
You can also use the "<" operator (you might already know from bash) to read a file.
my $content < io("the-file");
Writing to a file is also really easy and straight forward compared to the standard way.
open my $fh, ">", "the-file";
print $fh "Hello World\n"; 
close $fh;
With IO::All it is - as you may expect - only one line.
"Hello World\n" > io("the-file");
If you want to append to a file you can just use the ">>" operator.
"Hello World\n" >> io("the-file");

Special File Operations

With IO::All it is also easy to manipulate files without much code.

For example if you want to edit a special line inside a file you can do this with the following code:
my $file = io("the-file");
$file->[10] = "New content in Line eleven";
print $file->[20];

Directory Operations

 If you want to read the contents of a directory in the past you had code like this:
my @contents; 
opendir my $dh, "/dir";
while(my $entry = readdir($dh)) {    
    next if($entry eq "." || $entry eq "..");
    push @contents, $entry;
closedir $dh;
With IO::All you can reduce this to a one liner:
my @contents = io("/dir")->all;
With this function it is also easy to traverse subdirectories.
my @contents = io("/dir")->all(0);
Or, if you don't want to go through every subdirectory you can specify the depth.
my @contents = io("/dir")->all(2);