Perl / [Из песочницы] Perl - Сигналы / слоты и EV (libev)
16 November, 08:58, by kirichenko, machine translated from Spanish
Worldwide Perl Blogging
Totally
311 feeds,
9627 posts.
16 November, 08:58, by kirichenko, machine translated from Spanish
22 April, 05:05, by Jose Rey, machine translated from Spanish
push , shift , unshift , pop and slice now support allowing you to change the code references:
push @{ $arr->[1] }, 8
$head = shift @{ $obj->arrayref }
push $arr->[1], 8
$head = shift $obj->arrayref
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}} ) {...}
for ( @{ $obj->arrayref } ) { ... }
for ( 0 .. @{ $obj->arrayref } ) { ... }
for ( keys $hoh->{genres}{artists} ) {...}
|----------------------------+---------------------------|
| 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 |
|----------------------------+---------------------------|
{
package Uno;
...
}
{
package Dos;
...
}
...
package Uno {
...
}
package Dos {
...
}
...
$result = do {
my $ret = $text;
$ret =~ s/pedro/juan/;
$ret;
};
$result = $text =~ s/pedro/juan/r
tr///r(cond ...) in 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
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. 
9 October, 00:50, by Jose Rey, machine translated from Spanish
6 October, 02:04, by Jose Rey, machine translated from Spanish
6 October, 01:04, by Jose Rey, machine translated from Spanish
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.
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
7 June, 17:18, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
6 June, 19:09, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
6 June, 11:35, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
6 June, 11:26, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
6 June, 11:21, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
6 June, 11:18, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
5 June, 20:10, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
4 June, 20:34, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
1 May, 17:05, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
1 May, 17:01, by Skriptke, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
26 April, 13:48, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
25 April, 19:15, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
25 April, 12:23, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
25 April, 10:05, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
24 April, 01:20, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
23 April, 18:08, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
13 April, 17:31, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
6 April, 12:29, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
3 April, 17:31, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
2 April, 12:07, by Webmaster, machine translated from Spanish
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 Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
26 March, 22:36, by Webmaster, machine translated from Spanish
Perl Hispano :: Tutoriales de perl en español, recursos y manuales de perl cgi en español
26 March, 22:34, by Webmaster, machine translated from Spanish
18 March, 01:48, by Jose Rey, machine translated from Spanish
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) |
10 February, 03:47, by g013m, machine translated from Spanish
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.
aptitude install --without-recommends openerp-serversu - postgres -c "createuser --createdb --no-createrole --pwprompt openerp"/etc/init.d/openerp-server restartWith 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:
sudo aptitude install python-cherrypy3 python-formencode python-simplejson python-mako python-pybabel31 January, 11:56, by Jose Rey, machine translated from Spanish
18 January, 12:49, by Jose Rey, machine translated from Spanish
11 January, 05:14, by Jose Rey, machine translated from Spanish
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 ( "<
4 January, 08:10, by Jose Rey, machine translated from Spanish
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)
1 package Point; </
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:
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 |
24 December, 06:56, by Jose Rey, machine translated from Spanish
1 package Point;
2 use Moose;
3
4 has 'x' => (is => 'rw', isa => 'Int', default => 0);
5 has 'y' => (is => 'rw', isa => 'Int', def
7 December, 13:06, by Jose Rey, machine translated from Spanish
$ ab -n 1000 -c 10 -k "http://localhost:5000/cgi-bin/perldocweb?pod=PSGI&format=source"| 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 |
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
6 December, 23:56, by Jose Rey, machine translated from Spanish
CGI::Emulate::PSGI malfunctioned, because the global variables do not restart of CGI1 use CGI:: Emulate:: PSGI;
2 use CGI;
3
4 my $ app = CGI:: Emulate:: PSGI-> handler (sub (
5 CGI:: initialize_globals ();
6 do "perldocweb";
7))
30 November, 05:49, by Jose Rey, machine translated from Spanish
perl-MIO:: All-e 'io ( ": 8080") -> fork -> accept -> (sub ($ _ [0] <io (-x $ 1? ". / $ 1 |": $ 1) if / ^ GET \ / (.*) /)) '
30 November, 04:32, by Jose Rey, machine translated from Spanish
21 November, 12:50, by Jose Rey, machine translated from Spanish
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 (
15 November, 23:17, by Jose Rey, machine translated from Spanish
1 use CGI;
2 use Pod:: Simple:: HTML;
3
4 my $ q =
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? ..
DGAL logo
5 November, 04:25, by Jose Rey, machine translated from Spanish
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";
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.eval was successful or not, and that is in the special variable $@ (also known as $EVAL_ERROR if we use the module Español).$@ after eval1 use Modern:: Perl;
2 my $ result = eval ( "
24 October, 14:31, by Jose Rey, machine translated from Spanish
5 October, 14:47, by Jose Rey, machine translated from Spanish
34 $ command = ~ s / ^ \ s + / /, $ command = ~ s / \ s + $ / /;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
35 my @ args = split / \ s + /, $ command;
36 m $ oper = looks_like_number ($ args [0])? "Add_date": shift @ args;