Say Perl

Worldwide Perl Blogging

Totally
311 feeds,
9627 posts.

Perl / [Из песочницы] Perl - Сигналы / слоты и EV (libev)

16 November, 08:58, by kirichenko, machine translated from Spanish

В данной статье предложена реализация механизма сигналов и слотов в языке посредством модуля Perl EV ('perl-биндинг "libev к).

Perl is already 5.14

22 April, 05:05, by Jose Rey, machine translated from Spanish

few days ago came the first candidate for what will be Perl 5.14 (now we have new versions of perl all the time:) in this version are new and convenient features some optimizations (especially windows).

Symmetry between arrays, hashes and references

This is one of my favorite features of Perl 5.14, it simplifies the syntax when handling references.

In the case of the primitive arrangements as push , shift , unshift , pop and slice now support allowing you to change the code references:
 
push @{ $arr->[1] }, 8
$head = shift @{ $obj->arrayref }

for simpler versions that no longer need dereferencing:
 
push $arr->[1], 8
$head = shift $obj->arrayref

which certainly looks better, especially for beginners.

Adicionalmnete keys , values ​​and each reference system to work with hashes, but also work with arrays and reference system in the latter case, assume the values ​​of the array and the keys will be the integer indices, so they can do things like:
 
for ( values $obj->arrayref ) { ... }
for ( keys $obj->arrayref ) { ... }
for ( keys %{$hoh->{genres}{artists}} ) {...}

Instead of:
 
for ( @{ $obj->arrayref } ) { ... }
for ( 0 .. @{ $obj->arrayref } ) { ... }
for ( keys $hoh->{genres}{artists} ) {...}

also simplifying the syntax.

A table in the documentation gives several additional examples:
 
|----------------------------+---------------------------|
| Sintaxis tradicional | Sintaxis compacta |
|----------------------------+---------------------------|
| push @$arrayref, @stuff | push $arrayref, @stuff |
| unshift @$arrayref, @stuff | unshift $arrayref, @stuff |
| pop @$arrayref | pop $arrayref |
| shift @$arrayref | shift $arrayref |
| splice @$arrayref, 0, 2 | splice $arrayref, 0, 2 |
| keys %$hashref | keys $hashref |
| keys @$arrayref | keys $arrayref |
| values %$hashref | values $hashref |
| values @$arrayref | values $arrayref |
| ($k,$v) = each %$hashref | ($k,$v) = each $hashref |
| ($k,$v) = each @$arrayref | ($k,$v) = each $arrayref |
|----------------------------+---------------------------|

Block Packages

Usually when a script is done quickly, is easier to declare the packages (classes) in the same file, just as it is easy to fall into a trap because they have several packages in the same lexical environment, and when declared pragmas or lexical variables, they end up affecting other classes or packages because the statements are as lexically scoped to the entire file, the standard way around this is to declare each class within a block that limits its scope lexical
 
{
package Uno;
...
}
{
package Dos;
...
}
...

In perl 5.14 A package can have a block, making the building look better before:
 
package Uno {
...
}
package Dos {
...
}
...

Nondestructive substitution

Is implemented using the / ra a substitution, making the variable linked to the operation is not affected by it, instead it will return the modified value, so the following code:
 
$result = do {
my $ret = $text;
$ret =~ s/pedro/juan/;
$ret;
};

Can be written more concisely in 5.14:
 
$result = $text =~ s/pedro/juan/r

This switch was also added to the transliteration: tr///r

Given returns values

Lisp being a fan of this feature I liked, as they often simulate soil (cond ...) in Perl

Preparing a development environment for Perl

20 February, 04:50, by Christian Sánchez, machine translated from Spanish

Generally when developing with Perl, you need to use some modules or libraries that provide us with enough work, because they offer features ready to add to our programs and we save enough lines of code (and many hours of work we can invest to better ;) .)

There are 2 basic ways to install the libraries:

1 - Using the packaged libraries provided by our
Linux distribution
2 - Straight from the module repository CPAN

For the first option we can use the package manager (synaptic or aptitude from the command line in the case of Debian and derivatives), for example if we wanted to install a module that handles HTML templates in Perl HTML:: Template can run from the command line:

sudo aptitude install libhtml-template-perl

with it to install and configure the module and its dependencies in our system. Quick and easy, the problem is that often there are libraries that can not install this way, or something older versions are available. When this happens to us, we can use the 2nd way to install modules directly from CPAN.

To install modules from CPAN need to use the command "cpan", but there are a couple of problems with this approach: we need to have administrative permissions (perhaps in our machines is not a
problem) and the other downside is that there may be conflicts between versions of the libraries you downloaded and we have in our system already installed.
But there is a solution for this, which gives us the ease of installing any libraries it needs, without having to deal with administrative and / or native library versions of the system: local:: lib and App:: cpanminus .

local:: lib allows us to install the libraries you need in your home directory in a folder called "perl5" is practically create an isolated environment of the system, where we will have total control of the modules we install. Installation and use is quite simple, we summarize the steps:

- IMPORTANT: do all of the following as an unprivileged user, ie your normal user, if they do it as root does not make much sense ;) .
- Download the following file in your home folder (or any other
of preference): http://search.cpan.org/CPAN/authors/id/A/AP/APEIRON/local-lib-1.008001.tar.gz
- Unzip the file
- Enter the folder that is created when you unzip the file from the console, we'll need to run a few commands.
- Run the command:

perl Makefile.PL --bootstrap

there will be some questions we can answer and leave the defaults.

- Then run the command:

make test && make install

- We need to add the required environment variables to our meeting so that the Perl interpreter using the libraries of our home folder and not from the system, we do that by running the command:

echo 'eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)' >>~/.bashrc

- Close the console you're using, and open a new one that changes can be recognized in the new session.

We already have our directory to install modules now use App:: cpanminus to be ordered to do the job of installing and configuring them:

- We need to download the script to do the installation:

curl -LO http://xrl.us/cpanm

- We execute permissions to the script you just downloaded:

c hmo

Modern Perl book

15 November, 00:32, by Christian Sánchez, machine translated from Spanish

If you want to meet and begin programming in one of the best languages are ;) You can buy or download the book of chromatic Modern Perl . A book quite comprehensive and well designed so that anyone can get the most out of Perl. Modern Perl

Moose accelerating

9 October, 00:50, by Jose Rey, machine translated from Spanish

The most recent and successful system for Perl OOP , is becoming ever faster.

The Moose blog can see that it works continuously to refine the resource consumption and improve the performance of this system, which in its latest version (1.15) is compiling a bit slower, while involving more code "online" accelerating program performance.

Non-traditional applications in Perl

6 October, 02:04, by Jose Rey, machine translated from Spanish

I just saw an application of those who may initially not have occurred to me to do in Perl: " The Lacuna Expanse ", this application is a game and is massively parallel, so I have investigated as do it in Erlang or Haskell, but the server made 100% in Perl, the generic client is in JavaScript and then there are other mobile phone customers in a variety of languages.

It exploits the use of JSON RPC, and allowed them to use CPAN Plack , Moose , DBIx:: Class and the star of the party: JSON:: RPC:: Dispatcher .

Here is the trailer to hallucinate.

My favorite supplier

6 October, 01:04, by Jose Rey, machine translated from Spanish

Today I interviewed a supplier that could become one of my favorites, I'm doing a free interpretation of the conversation and perhaps imagine it is favorably impressed:

Me: I called because I am overwhelmed with so many things to do and need someone to help migrate Oracle databases and PowerBuilder applications.

Provider: We specialize in Power Builder and Oracle among others, but we are working hard with PostgreSQL, Perl, Python.

Me: And if they ask for help to migrate PowerBuilder applications to the Web that I recommend technologies.

Vendor: Well, we worked mainly with Python using Django, which is an excellent environment, however, we realized that although Perl is not so nice, we are paying more for our work, so lately we are working more with Catalyst and Perl in general.

I need more suppliers as well, because where I work if we are to migrate to free software.

App:: Perlbrew, trying out different versions of Perl easily

14 August, 16:29, by g013m, machine translated from Spanish

Most Unix-based operating systems come with a version of Perl installed, depending on how updated this system we have the latest version of the language. For example in Debian Testing (Squeeze yet) have the 5.10.1 version in Mac OSX Snow Leopard version 5.10.0 (I put these two examples because they are operating systems that use). If we wanted to try some newer version of Perl could install from source or maybe using packages. Deb in the case of Debian, but maybe we have some problems with the agencies and could harm our base system.

There is a tool that facilitates the installation and management of different versions of Perl simultaneously on the same machine App:: Perlbrew . This application is responsible for creating a complete environment of Perl in your home directory, you can handle without having administrator privileges, this brings many advantages as it allows us to prove anything without the use of (damaging) our base system. Everything we install (CPAN modules) is within this environment, applications that we would try to use this environment also, then we can see the operation of the same in different versions of Perl, with different versions of modules, etc. the possibilities are many. Even we have an older version of Perl, perhaps 5.8, as there are many people who have not yet migrated to 5.10 and so we can ensure that our programs run on any of the various versions of Perl.

Installation is quite simple, you do not need administrator permissions and everything will be stored in our user directory. What is recommended for installation is to get it directly from the developer's site:

curl -LO http://xrl.us/perlbrew

then give the script execute permissions:

chmod +x perlbrew

and finally execute the script:

./perlbrew install

And with that we have installed perlbrew and we can start using it, for basic configurations run the following command:

perlbrew init

and follow the instructions that appear to us, which in reality is to add some environment variables to the file. bashrc. After this configuration step, we are ready to install any version of Perl we need, for example:

perlbrew install perl-5.12.1

after waiting for you to download and configure, we may use that version of Perl as follows:

perlbrew switch perl-5.12.1

this will change our environment, the documentation recommends running the hash-r command to clear the cache of the PATH variable, after this when you run perl-v should be working with the newly installed version of Perl. Everything you install using CPAN is within this environment.

If you then want to "turn off" here, we can run the command:

perlbrew off

and return to our boring Perl installation base system.

We can set the number of versions we want to list which we have installed run the command:

perlbrew installed

This is a good way to start testing Perl, if you have not already done so.

A photographic album Modern Perl:: Part 3

7 June, 17:18, by Webmaster, machine translated from Spanish

good as I have not much time, but I want to go for now the only thing I did was to create styles for the design of Perl photo gallery, just edit the HTML templates

album.html
code

Perl functions

6 June, 19:09, by Webmaster, machine translated from Spanish

is just a list of some of the most used functions in perl, on other items are explained more thoroughly and in detail the functions of Perl

abs: Returns the absolute value of last expression.
chmod: change permissions ...

bless function in Perl

6 June, 11:35, by Webmaster, machine translated from Spanish

Syntax

REFERENCE bless

Action

Complete reference with a statement of the package to which it belongs.

Instance

BOX package;
(
$ Var = "333";
$ Ref = \ $ var;
...

binmode function in Perl

6 June, 11:26, by Webmaster, machine translated from Spanish

Syntax

binmode MANIPULATOR

Action

Create a "filter" through which pass the data file associated with handle. Reading them translate the character CR (carriage return, ASCII 10) by CR LF (Return ...

atan2 function in Perl

6 June, 11:21, by Webmaster, machine translated from Spanish

Syntax
atan2 Y, X

Action

Calculates the arc tangent of Y / X in the range

Instance

$ _ = Atan2 0, 90;

abs function in Perl

6 June, 11:18, by Webmaster, machine translated from Spanish

Syntax

abs EXPRESSION

Action

Calculate the absolute value of EXPRESSION

Instance
$ _ = Abs 3 -8;

html read parameters in Perl

5 June, 20:10, by Webmaster, machine translated from Spanish

Well how to read parameters in the most standard Perl you can use if we do not use a frameworks like Catalyst or CGI-Application is the CGI module


code #! usr / bin / perl

use CGI;

print param ('foo');

# Suppose ...

Find and replace text in Perl

4 June, 20:34, by Webmaster, machine translated from Spanish

Ok go if you want to find and replace text in a string in Perl is very easy


code

# $ Variable = ~ s / pattern / replacement /;


$ Mystring = "I want to play with my cat"
$ Mystring = ~ s / cat / dog /;

print ...

Screencast: Dancer sample application with

1 May, 17:05, by Webmaster, machine translated from Spanish

Article of Blackshell
blog on Free Software, networks, systems development and

One of the things that I feel great Dancer is it does not get in your way when you are developing: your problem is the application you want ...

Nes Plugin Template with CGI:: Application

1 May, 17:01, by Skriptke, machine translated from Spanish

New Plugin with which you can use templates of Nes in applications created with CGI:: Application.

CPAN: http://search.cpan.org/dist/CGI-Application-Plugin-Nes/

Example: ...

Melody First version to download

26 April, 13:48, by Webmaster, machine translated from Spanish

has just been published a compiled list to download and install the fork of Movable Type called Melody. This corresponds to an alpha version so is not recommended for production environments, rather it is recommended to install to help ...

A photographic album Modern Perl:: Part 2

25 April, 19:15, by Webmaster, machine translated from Spanish

Well in this second part of how to develop Perl image gallery, first create the controller in CGI:: Application for the manipulation of data, basic html templates and consultation the database.

the gallery.pl is very ...

A photographic album Modern Perl:: Part 1

25 April, 12:23, by Webmaster, machine translated from Spanish

This is a project of developing a system of galleries in modern Perl.


For the development of this photo album we will use CGI:: Application, if you do not know how to use it do not worry I did not know, but it works well and will use ...

How to put HTML code in Perl the easy way

25 April, 10:05, by Webmaster, machine translated from Spanish

As emebeder Perl in HTML, Perl code to HTML ... always ask this

This seems to be a big problem or a grand dilemma, well it turns out that as users of Linux do that with my intermediate knowledge of things required a rest ...

Perl Web Service Client

24 April, 01:20, by Webmaster, machine translated from Spanish

In this document we will learn to call a Web Service (Web Service) with Perl.

As we know, all communication with a Web service is done via SOAP (an acronym for Simple Object Access Protocol) and this allows us ...

Create a website with Perl and mysql

23 April, 18:08, by Webmaster, machine translated from Spanish

Actually there are many ways to do this same task in Perl
illustrate the faster using the module Template:: Toolkit which according to my statistics come installed by default on all hosting CPANEL ..


If you want to see if the ...

Cornelia:: Operating System on the Web in Perl

13 April, 17:31, by Webmaster, machine translated from Spanish

Perl forward and making new force in the web with small, medium and large projects in this case Cornelius

A web operating system ("Web OS") running in your browser. All applications and files are stored in the ...

CMS in Perl

6 April, 12:29, by Webmaster, machine translated from Spanish

What is the best cms in Perl?
The most powerful Perl cms.
Because there are so many CMS in Perl?
The decision to develop a CMS in Perl?

Are some of the questions that try to respond.

Nowadays ...

Sort array or list in Perl

3 April, 17:31, by Webmaster, machine translated from Spanish

One of the ways to sort a hash by key is as follows:


SimplePerl CMS Project 2.0

2 April, 12:07, by Webmaster, machine translated from Spanish

was born in a Hispanic Perl CMS development project in Perl.

I am developing a CMS framework in Perl with CGI:: Application. I HOPE SOMEONE HELP, is easy to work but I have 614 lines of code ... and handles up templates, but ...

Dancing with Perl - Dancer

31 March, 18:18, by g013m, machine translated from Spanish

Dancer is a lightweight web framework that allows us to build applications quickly and easily. It is an excellent alternative when you do not want to write CGI scripts by hand, Catalyst is too cumbersome to implement. Like any other framework brings an embedded web server for testing and can run with other Web servers using PSGI / Planck .

To install it we can do it directly from CPAN by running the command:

sudo cpan Dancer

Not have official packages for Debian (or derivatives), I did the package and the dependencies it needs, can download from here:

libhttp-server-simple-perl , you will need version> = 0.42, Debian is still the 0.41
libhttp-server-simple-perl-PSGI
libdancer-perl

After having installed Dancer, create a new application is as simple as:

dancer -a miaplicacion

This command creates a simple structure of the application, the following would change the routes to be used, in this case that is on file miaplicacion.pm:

 1
2
3
4
5
6
7
8
9
10
11
 Dancer use;

get '/' => sub (
    return 'Hello World! "
);

get '/: name' => sub (
  return "Hello." params -> (name);
);

dance; 

Dancer has many more options, such as content formats back JSON, XML, YAML directly without processing or perform different actions (think of a webservice that returns JSON content for other applications ...), use of templates, management sessions, etc. In addition you can integrate with other CPAN modules to achieve more sophisticated applications.

A good choice for simple applications, and without much effort ;)

Perl-Catalyst in Spanish Tutorial Part 2

26 March, 22:36, by Webmaster, machine translated from Spanish

Catalyst Web Framework - Part II
In the previous post we played a little with the inception of the project, controller and view. Now let's have fun with the modification of our Helper (Assistant or Assistant Hits) TTSite to include ...

Perl-Catalyst in Spanish Tutorial part 1

26 March, 22:34, by Webmaster, machine translated from Spanish

Catalyst Web Framework - Part One
What is a Framework?
It is a set of tools that are integrated or make communication with each other to solve a job
particular.

What is MVC?
It is a methodology or style ...

A tutorial in Spanish catalyst

18 March, 01:48, by Jose Rey, machine translated from Spanish

As collapsed'm unable to write, I leave the blog of a friend who will write a series of articles on Catalyst.

Game of Life in Perl

5 March, 02:57, by g013m, machine translated from Spanish

Reviewing some saved files that did work for classes in college, I got a program in Perl for a course called Emergent Computing. It is an implementation of the game of life fairly simple, what's interesting is that nobody on the course knew something about Perl, and they all implement in Matlab, that as it was easier to handle arrays, and do the iterations , etc, etc. .. so I thought I do this using other tools, and this is what came out, the idea is to create an array of N x N and execute all rules or algorithms in a number of iterations. The code can perhaps improve, but this was enough to get 20 in this assignment ;) :

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 #! / usr / share / bin / perl

Modern use:: Perl;
use Math:: MatrixReal;

say "Enter the amount of N, the creation of an NxN grid:";
my $ n = <STDIN>;
chomp ($ n)

Installing Debian Lenny OpenERP

10 February, 03:47, by g013m, machine translated from Spanish

OpenERP OpenERP is one of the best open source solutions to business and business. It has very well-structured scheme of modules and extensions easily adaptable to any business scenario.
There are packages ready to install Debian Squeeze (testing), but there are none for Debian Lenny (stable), you can install from source to hand down some units and making some adjustments, but that's not the Debian Way ;) . You can download packages and install Squeeze hand but still have to resolve some dependencies, so one option is to use directly the Squeeze on Lenny repositories. This could cause some problems in a production server, because some packages may be upgraded to newer versions and break dependencies with others, so we must consider this before doing something and watch for changes that will to do before installing anything.

  • The first thing we do is modify the list of repositories and add a line with a repository of Squeeze, may be one of them we have in "/ etc / apt / sources.list" and change "stable" or "lenny" by "squeeze", save changes and update the list of packages with "aptitude update".
  • OpenERP works with PostgreSQL so we will need to install it, this is installed as a recommendation OpenERP and be using the Squeeze repositories will ask to install the latest version available to date is 8.4, so if you already have installed PostgreSQL server uses the following line to install only the server OpenERP and the necessary dependencies: aptitude install --without-recommends openerp-server
    This install only what is necessary to have the server running OpenERP.
  • Then we can install some other packages recommended by OpenERP-server package
    aptitude install python-imaging python-python-openssl-dev libxslt1 pyparsing
  • We need a user for the server postgresql OpenERP, we can create with the following command:
    su - postgres -c "createuser --createdb --no-createrole --pwprompt openerp"
    With this line we are creating a user called "OpenERP" you can use another name, also will ask for a password that is that we will use later to make the connection to the database
  • We must edit / etc / OpenERP-server.conf to add the user password DB
  • Restart the service OpenERP:
    /etc/init.d/openerp-server restart

With these steps, you have the server up and running OpenERP, what remains is to configure it, we can do that using the client OpenERP, there is a version written in GTK, which can be installed directly with: aptitude install OpenERP-client. The other way is to use the web client, as you are using a server that can be installed on the same machine and access from any machine directly using only a browser. There is no Debian package yet to the Web client, there is one being prepared, but it worked well after installation, so I used the option to install it by hand, the steps to making it work would be:

  • We unloaded the web client OpenERP Page
  • The web client is written in Python and need to install some libraries for it to work properly, we can install these packages with the following line:
    sudo aptitude install python-cherrypy3 python-formencode python-simplejson python-mako python-pybabel
  • This client runs a service that runs by default on port 8080, so we can run it from wherever we want, in my case I copied the contents of the folder in / opt / OpenERP-web /, from there we can p

Moose diet

31 January, 11:56, by Jose Rey, machine translated from Spanish

[Versión original]

Do you think that Moose is too heavy for your applications?

The collection of objects of Moose can take considerable time during the startup of an application, this could give the impression that programs that use Moose is slow, however the compilation only happens when loading the program, and depending on the application could be that Moose is not as heavy as it looks.

One example is an application in Catalyst (in older versions of 5.8), when it starts it should compile all objects made in Moose and feel the difference with previous versions, but as Catalyst is to run for days or months does not matter much boot time.

If the application you want to develop is a command that executes a task completed quickly and perhaps Moose is too heavy for you, especially when repeatedly execute commands via other commands like xargs (1) or find (1).

For cases where the starting time of the application will not be amortized along with the implementation, there is a solution in the CPAN: Mouse.

Mouse is a replacement for Moose highly optimized that allows the vast majority of the features of Moose, but is much lighter because it is developed in XS (ie C) and omit some features to ease the implementation.

According to the manual page Mouse, Moose fails only 1% of tests Mouse, making the latter very compatible with the first, but the battery of tests is run 400% faster and in my experience I can not tell the difference between using

Sweet sweet Moose

18 January, 12:49, by Jose Rey, machine translated from Spanish

[Versión original]

One comment I received for the above article was about how it would use the syntax of MooseX:: Declare.

This module provides syntax extensions that go far beyond the regular syntactic sugar Moose. Using the black magic of Devel:: Declare, MooseX:: Declare creates a whole new syntax very similar to Perl6, to declare the classes and roles Moose, however, the use of these extensions I generates mixed feelings.

On one side is the look and simplicity of the syntax implemented by the module, and moreover I noticed that changing the syntax in this way will stop working tools that I take for granted, like perltidy, which gives errors in the statement prototyping methods, also falters modules such as PPI and even vim coloring.

I am aware that it is all about repairing perltidy, PPI and vim coloring, but the detail is that it is difficult to implement as much syntax occur to anyone to introduce new modules in CPAN.

I have always argued that one advantage of Devel:: Declare is that it allows Perl5 evolve through CPAN modules as TryCatch and MooseX:: Declare show syntactic extensions that could eventually be added to Perl5 of widely accepted.

But how will become widely accepted, if not break the tools we use because we would normally use?

Maybe none of this matters because in March 2010 comes Rakudas *, and everybody will start the great migration to Perl6.

As I do have the same number of arguments pro and cont

Evolution of style in Perl

11 January, 05:14, by Jose Rey, machine translated from Spanish

[Versión original]

The techniques and style in programming is one of those things that change over time, as Perl can easily extend the language, forms a circle when you turn evolutionary extensions popularize new styles of programming.

Today I try to give a quick look at several ways to program in Perl that I've used over the years, with the hope that you can appreciate the advantages of modern programming style in Perl.

All programs in this article have the same goal, to play the game animals, giving the illusion that the computer learns. However, not all programs use the same data structures or achieve the same level of robustness, in this sense the styles "old" are less robust than modern.

Old Perl5


In Perl5 early computers were less able, so programs written often quite compact, it also used "clever tricks" such as the use of hashes in this program, which is not exactly easy to understand how it works % tree in the program:

Style 1: Old
 1 #! / Usr / bin / env perl 
2 sub prompt (
3 print $ _ [0];
4 $ line = <>;
5 chomp $ line;
6 $ line;
7)
8
9 sub if (
10 prompt ( "<

Moose attributes with traits.

4 January, 08:10, by Jose Rey, machine translated from Spanish

[Google translation]
In the previous article we saw the basics of Moose, but once you start to learn this system you will see that OOP has a lot of mechanisms (and concepts) that make many things, one of the most useful features (traits) , allowing to apply behaviors to a class or attribute easily.

A characteristic of the attributes are features that facilitate the use of them and allow more efficient operations.

An example, using the Point class from previous article to which I will add the translate method, which moved one point:

 23 sub   translate ( 
24 m ($ self, $ x_delta, $ y_delta) = @ _;
25 $ self -> x ($ self -> x + $ x_delta);
26 $ self -> y ($ self -> y + $ y_delta);
27)

As you can see, the handling of attributes is tedious, here is where the features begin to be useful, in particular the coordinates of a point with numerical features, lets see how improving the code when we apply:

 1 package Point; </

Using Perl to extract data from Excel files

4 January, 02:51, by g013m, machine translated from Spanish

There is a (bad) habit of storing data in excel files in many organizations, large or small, this works when the data are many and can be handled quickly, but generally this information grows and becomes more difficult to maintain data integrity, sometimes you have multiple versions. xls file, are sometimes lost or erased accidentally, and so on.

After going through all these problems, you implement any information system that can handle all data more efficiently, and clearly not going to start building again for records that already have many. Xls files. That's when they begin to seek solutions to extract this data quickly, and that's where Perl comes to the rescue ;) . There is a module (among many) that allow us to work with. Xls files without opening them one by one being Spreadsheet:: ParseExcel, this module allows us to open excel file and extract all the information it contains. I will create a small example of the operation of the module, suppose we have an excel file with the following structure:

Archivo Excel

Excel File

A file with 4 columns, in this case correspond to the following information: Name, Last Name, Decree and Mail. These data are stored in the table "person" in a Postgresql DB.

Records should be drawn excel file, identify the fields, and then store in the DB, an example of how this can be done with Perl and Spreadsheet:: ParseExcel is the following script:

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 #! / usr / bin / perl
Mo use

Knowing the moose (Moose)

24 December, 06:56, by Jose Rey, machine translated from Spanish

On other occasions I have spoken of the Moose, today I will explain the basics of this new system of object-oriented programming has taken by assault on CPAN and that many developments are taking as a platform formal object-oriented programming.

All this noise is because Moose ofece unique mechanisms of code reuse and polymorphism are also very easy to use. So now in addition to the inheritance you can use roles (also known as mixins), have the ability to easily change the behavior of a class for a role, you can delegate one class into another magically, into contracts, lazy initialization, type checking and dozens of new features that will make you think how could you schedule your life without them.

Direct manual Moose a simple example of implementation of inheritance:

 1 package Point; 
2 use Moose;
3
4 has 'x' => (is => 'rw', isa => 'Int', default => 0);
5 has 'y' => (is => 'rw', isa => 'Int', def

Performance PSGI / Plack

7 December, 13:06, by Jose Rey, machine translated from Spanish

[Versión original]
In my article on PSGI Plack said that he was quick to demonstrate compare the speed of the program running as CGI in Apache (ACGI) as a standalone server in CGI:: Emulate:: PSGI (CEP) and as a native application PSGI.

The test was very rigorous, because I really just wanted to confirm what he read.

The command to report the rate was:

$ ab -n 1000 -c 10 -k "http://localhost:5000/cgi-bin/perldocweb?pod=PSGI&format=source"

The results were:

ACGI
Zip
PSGI
Requests / sec.
10.57
267.17
512.31
Runtime (ms)
94,618
3,743
1,952
Rat transf. (kbps)
179.52
4539.79
8686.67

Just to see the raw speed, I made a small program to serve text files and compare the performance against Apache serving static files:

 1 #! / Usr / bin / perl 
2
3 use Modern:: Perl;
4 use IO:: File;
5
6 my $ dir = "/ home / jrey / htdocs";
7
8 m $ app = sub

Error in CGI:: Emulate:: PSGI

6 December, 23:56, by Jose Rey, machine translated from Spanish

While working with the code of the previous article, I realized that in fact the example of CGI::Emulate::PSGI malfunctioned, because the global variables do not restart of CGI

 1 use CGI:: Emulate:: PSGI; 
2 use CGI;
3
4 my $ app = CGI:: Emulate:: PSGI-> handler (sub (
5 CGI:: initialize_globals ();
6 do "perldocweb";
7))

Otherwise the first request parameters remain fixed forever.

PSGI and Planck: The future of web applications

30 November, 05:49, by Jose Rey, machine translated from Spanish

[Versión original]
A few weeks ago I showed my friend Joel a one-liner in Perl it featured a web server, perhaps had too much work to do because it did not seem surprised by this fantastic line of perl module using IO:: All:

 perl-MIO:: All-e 'io ( ": 8080") -> fork -> accept -> (sub   ($ _ [0] <io (-x $ 1? ". / $ 1 |": $ 1) if / ^ GET \ / (.*)   /)) ' 

But surprisingly well (especially for a fan of Perl) his response was: "You know that people have software to deploy Python web servers with many facilities, but not what," I noticed there did not understand the point , perhaps the grip at a bad time so I let him go.

But I was intrigued, but he was sure he was referring to WSGI (also known as PEP-333): a specification for a web application API, allowing the separation and responsibilities between the interface (policy) and implementation (mechanisms) so that developers can develop and optimize worry about whether mechanisms that use applications.

In Perl this was the work of HTTP:: Engine used among others by Catalyst.

PSGI and Planck: The future of web applications

30 November, 04:32, by Jose Rey, machine translated from Spanish

This article should not have published here, I moved to where it belongs in Perliscopio, sorry for the inconvenience.

This should not be published here, I moved the article where it belongs at Perliscopio, sorry for the inconvenience.

POD Processing with Pod:: Simple

21 November, 12:50, by Jose Rey, machine translated from Spanish

[Versión original]
In the previous article we convert POD to HTML with relative ease for a tiny document server with CGI fact, today I will expand the program, allowing the visualization of POD documents in a dozen different ways.


A useful option when I see the documentation CPAN, is the ability to display the sources of the modules, so I'll add a link that can view the source of a document, I'll put the link at the bottom of the document, setting the footer HTML conversion, I must also add logic to recognize the new type of link.

I will add a formatting switch (format) to the query, and I play it with the given line 12, in addition to being compatible with the previous version, I will allow the format is optional and its default value is HTML (line 11):

 1 #! / Usr / bin / perl 
2
3 use Modern:: Perl;
4 use CGI;
5 use CGI:: Carp 'fatalsToBrowser';
6 use Pod:: Simple:: Search;
7 use Pod:: Simple:: HTML;
8
9 my $ q = new CGI;
10 my $ filename = Pod:: Simple:: Search-> new -> inc (1) -> find ($ q -> param (

Perl documentation tools

15 November, 23:17, by Jose Rey, machine translated from Spanish

[Versión original]
Perl has its own documentation format called POD (Plain Old Documentation English), this format is structured and was specifically designed to be easily manipulated. POD is used not only as a tool for documenting Perl, but as Wiki language and even writing books.

In perl the most popular tool for reading the documentation is perldoc, which works very similarly to the unix manual man (1), so when we see the documentation of a module can do:

$ Perldoc IO:: Handle

What we will show the manual IO:: Handle, we can get the manual module in a variety of other formats, for example, we can save the file in "man", HTML or LaTeX:

$ Perldoc-T-o LaTeX IO:: Handle> IO:: Handle.tex
$ Perldoc-T-or html IO:: Handle> IO:: Handle.html

If we see the generated HTML you will realize that the links generated by other documentation relating to the CPAN, but this is just the way it works perldoc, there are hundreds of modules to process POD, enabling advanced manipulation and convert it to HTML , XML, LaTeX, text, and DocBook, and others.

When you need more control over the generation of documents, you can use other tools such as: pod2html and pod2latex that create documents based on multiple POD files are processed together, for example to make a book where each chapter is stored in a POD different.

If you need total control over the conversion of POD, you can always program using the modules available on CPAN, and one of the easiest is to use Pod:: Simple, which offers several predefined conversions, for example if you generate HTML in an application CGI, you can do with ease:

 1 use CGI; 
2 use Pod:: Simple:: HTML;
3
4 my $ q =

Ubuntu is up to agencies celebrations ..

7 November, 02:48, by g013m, machine translated from Spanish

Not that I use as a technology platform, but as a basis for the graphic design of its logo, and the resemblance between the logo of "Tell them" and Ubuntu gives much food for thought, perhaps the designer uses ubuntu?, " may not have much inspiration and saw the logo out there? Or perhaps it is too coincidental and did not know that it is almost identical to the logo of this distribution? ..

logo dgala

DGAL logo

Error Handling in Perl

5 November, 04:25, by Jose Rey, machine translated from Spanish

[Español Translation]

In Perl exception handling is a bit different than we are probably used to, particularly Perl has no try / catch / throw as some other languages, but does not mean that no exception handling, Perl can catch and handle exceptions as well as any other language that structures are only slightly different.

Exception handling in Perl is based on the operator's use eval which allows eval uar code and catch errors when eval receives a string, compiles the code is in the chain and runs, but any errors that happen in this code from compilation through execution will abort only the eval and our program will continue to function, for example:

 1 use Modern:: Perl; 
2 my $ result = eval ( "5 / 0");
3 Say "The result: $ result";

Although the program works, the result of eval is undef because division by zero prevented the return of any value, this also causes a warning on line 3 on the chain with a variable undefined.

What we need is whether the eval was successful or not, and that is in the special variable $@ (also known as $EVAL_ERROR if we use the module Español).

So to capture the only exception we check $@ after eval

 1 use Modern:: Perl; 
2 my $ result = eval ( "

Evolution of languages

24 October, 14:31, by Jose Rey, machine translated from Spanish

[Versión original]
Perhaps she has noticed that I have not written much lately, the reason was that I had to devote full emergency migration.
The system in question belongs to the client who hired me to develop a web application, which incidentally was my first application of this style back in 1998.


At that time was giving my first steps with Perl, but somehow convinced me that the application should be developed in PHP, I slowly realized that PHP was not flexible enough and end up doing several Perl programs that implement the most some of the functionality, yet the entire application interface remained in PHP.

During this project, I learned that Perl was much more versatile, powerful and fun than PHP, and if I had not been persuaded, would probably have succeeded CGI.pm, the entire application would be in Perl and not have a story to tell.

At the start of migration occurred to me that would be easier to make the interface work first because I thought that being the simplest part of the application could easily migrate to PHP5, this was far from reality, nothing worked as it should.

I understand that everything evolves, but is that not even compile programs, some APIs have changed enough to warrant a complete review of all source code, and of course it was disgusting, what else could it be?, In that time there was a library of templates, access to the database was done with the horrible library functions of PHP3, and the entire application is a monument to the ASP style programming, where the view, model and drivers were completely integrated, as if they had gone through the blender.

The truth is that it was easier to compile PHP3 in the new operating system to try to migrate the code to php5, so I thank archive.debian.org Debian and particularly, must be one of the few places on the planet sources still keep that (PHP3), because the language community has a policy of withdrawing from the Internet.

Having overcome the problem (ie PHP), I had nightmares about the pile of Perl 5 that would not work for nothing in the new Perl 5.10, so I resigned to copy all

Calculator Statistics: Finishing touches

5 October, 14:47, by Jose Rey, machine translated from Spanish

[Versión original]
In the previous article. slope we get the parameters and acknowledged interpreter was able to write any return value of functions in Statistics:: Descriptive.
First we define as separate commands of the parameters, and as separate parameters to each other, and the easiest way is to do as the shell, ie using blanks for both, so once you get a line of commands:
 34 $ command = ~ s / ^ \ s + / /, $ command = ~ s / \ s + $ / /; 
35 my @ args = split / \ s + /, $ command;
36 m $ oper = looks_like_number ($ args [0])? "Add_date": shift @ args;
spaces are removed at the beginning and end (34), separate all the elements separated by one or more white (35), and obtained the operation to perform (36) which is usually the first element, except numbers in which the operation is "add_date. After these operations have the operation to be performed in $ oper and its arguments