Portuguese Perl Workshop 2011
The Portuguese Perl Workshop is back. This year's event will be held in the 22nd and 23rd of September in sunny Lisbon, where the grass is green and the girls are pretty.
Check the official site for details.
The Portuguese Perl Workshop is back. This year's event will be held in the 22nd and 23rd of September in sunny Lisbon, where the grass is green and the girls are pretty.
Check the official site for details.
In Perl we can run user defined code blocks at different stages when running a program.
Here is an example of what a module can look like. In this case it only has a simple method that greets the user:
class Greeter;method greet($name = 'world') {
say "hello $name";
}
Now to use the module we can write something like:
BEGIN { @*INC.push('Greeter/lib') }
use Greeter;
my $x = Greeter.new;
$x.greet('rakudo');
The only tricky part is actually the push in the BEGIN block, to add your lib directory. Of course running this is as simple as:
$ ./perl6 greeter.p6 hello rakudo…
The fork function is a very powerful tool used among many languages. Unfortunately It's not that common among Perl scripts, maybe because most scripts don't really have a need for it. But it's a handy trick to keep inside your hat.
Fork creates a new process running the same program, usually the process that calls the fork is named the parent process, and the created process is named the child process. The fork function returns 0 to the child process, and the newly created process pid to the parent. Using fork can be as simple as:
print "($$) hello\n"; my $pid = fork; if ($p…