Introduction to the Perl Programming Language - Part 1

perl-onion

Agenda

  • What is Perl for
  • Development Environments (GUI)
  • Type of Variables
  • Print function
  • First Program: HolaBarcamp.pl
  • STDIN function
  • Second Program: WelcomeAlBarcamp.pl
  • Third Program: Basic Operations.pl
  • IF statement

This will be the first installment of Programming in Perl, this material will be used for the exhibition at BarCamp Milagro where I will be an exhibitor, it divides it into parts so as not to make the post too big, I hope you like it.

All the files mentioned in the article can be downloaded from this link:

Download fonts

For what to serve Perl

Perl is a multipurpose language, in which they can be done from small scripts to manage servers based on Unix o GNU / Linux, to make web pages, there are complete projects made in Perl

Development Environments

Currently on the market there are many development environments to program in perl of which we can name:

1.- SublimeText (Windows and GNU / Linux)

2.- Eclipse (Windows and GNU / Linux)

3.- OpenPerlIDE (Windows)

4.- Notepad ++ (Windows)

Type of Variables

In Perl as in all programming languages ​​there are different types of variables

* Scalars. Variables start with $, like $ variable. Strings of text or numbers are represented here.

* Arrays. Arrays start with @, like @variable. You can put whatever you want inside.

* Hash. Hashes start with%, as% variable. Both variables and data can be anything.

Scalar

$var1 = 33; #Esto es una Variables Global

My var=32; #Esto es una Variable Local

Arrays

@array = ( “uno”,”dos”,”tres” ); #Array 3 elementos

@array=(); #Array de x elementos (Indefinido)

Hash

%hash = ( 1, "uno", 2, "dos", 3, "tres" );

Print function

The function print as in the C ++ programming language, it is used to print a text string or the content of a variable on the screen

First Program: HolaBarcamp.pl

1

2

STDIN function

What we have worked for C o C++ have to remember the function scanf. Well, STDIN fulfills the same function which is to receive the values ​​entered by keyboard, but unlike scanf in which we had to tell it which value is going to be entered with STDIN, we only have to do this:

$variable=<STDIN>;

With STDIN you can enter text, number, alphanumeric, all this without defining how it was done with scanf:

scanf(“%d”, variable_tipo_entera);

Second Program: WelcomeAlBarcamp.pl

3

4

Third Program: Basic Operations.pl

With the above learned we can now make a program that performs the four basic operations

5

6

IF statement

The IF statement, as in any programming language, is used when we want to make validations or we need a process to be carried out when the if condition is met.

7

8


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   elav said

    Oh! Ok, let's learn Perl 😀

    1.    dhunter said

      Mother of God…. a Perl tutor in 2013, let that language die in peace, if you like "smart" languages, learn Ruby that inherits many things from Perl (the TIMTOWTD philosophy for example) but is much sexier.

      1.    ozkar said

        +5 And this Saturday you owe me a whiskey 😀

        1.    dhunter said

          No drinks per mua ... if I drink whiskey it is able to put python in a symfony controller.

      2.    leonardopc1991 said

        Yes, but I like Perl for handling files, and because it is oriented to scripts that help to schedule tasks on the server

        1.    dhunter said

          That's why I was telling you Ruby and not Python, Matz is a fan of Larry Wall and I copy a lot, that Perl code is unmaintainable, you wear out a lot of "brain-cicles" just understanding what the hell you did 3 months ago.

          I'm personally more of a Python fan. Zen has made me a devotee.

          "There should be one– and preferably only one –obvious way to do it."

          1.    leonardopc1991 said

            I also want to walk through Python and Ruby, but first I will finish at least the Perl xD Tutorial

          2.    Juan said

            It will be unmaintainable but very necessary, at least for me it means working or not. I am a researcher, GPS data processing and the mother languages ​​in the most important scientific software in the world for this task (there are no more than 4) are Fortran and Perl. In fact, whether they give me a Postdoc at the end of the thesis depends on my learning Perl, otherwise, as soon as my scholarship ends I will be unemployed and without any possibility of continuing. So to study Perl and not to go around the house and make a few scripts to replace texts in files, but seriously.
            You have an example in this recent offer:
            http://www.bernese.unibe.ch/Stellen/Stellenausschreibung_20140225.pdf
            Perl is one of the recommended ones. And I who am within this field of research, I can assure that the one who does not control some of these languages ​​has nothing to do.
            Thanks for any Perl tutorials you post.

      3.    Bad said

        Pffff thought the same until I got to do the practice and everything is programmed in perl. It shows that you have not left the classroom.

  2.   Andrés said

    Genie, will there be more of these installments, other languages ​​like Python 3 or Ruby?

    1.    Gaius baltar said

      Maybe you are already more advanced, but the University of Toronto has this free online Python course that is very good for those of us who don't even have a potato to program. 😀

      https://www.coursera.org/course/interactivepython

      1.    Andrés said

        Thanks, I was looking for something like this.

    2.    Gaius baltar said

      Sorry, the one I put is not the introductory one, it's another one 😀

  3.   Gaius baltar said

    OH !!!! I save it for when I finish the Python course !!! 😀

  4.   Stefano said

    Thanks Leonardo, I only ask you please if you can put the texts of the instructions instead of images 🙂

    1.    leonardopc1991 said

      I forgot I already put the link with the codes in GitHub

  5.   juanli said

    Orale !!! I did not think it was so similar to C ++ !! , Excelent topic!!

  6.   arlf said

    leonardopc1991 your way of writing is somewhat ugly, I recommend that you read the pep8 style (it is python but still works with other languages) here you have it in Spanish http://mundogeek.net/traducciones/guia-estilo-python.htm

    1.    leonardopc1991 said

      I will take it into account, the formatting of the code leaves it as it is Sublime Text 🙂

  7.   let's use linux said

    Great contribution!
    Congratulations!

  8.   juanra20 said

    Excellent contribution 😀 is very well explained and I like the examples.
    It would be good if at the last, and of course if you can, do an exercise in the tutorials demonstrating what Perl can do in GNU / Linux

  9.   Erick said

    The truth is very good and I will be looking forward to the next post, Greetings

  10.   Victor Franco said

    It may be old-fashioned but it never hurts to know a little of this language ... thanks for this tuto ...

  11.   spyker said

    All posts are welcome, but I do not see very normal that someone who is just learning a language already does tutorials on it.

    The printf function is characteristic of C, in C ++ it would be cout, the same as scanf.

    For the rest I do not know what to say, I do not know the language, but this entry is appreciated.

    1.    leonardopc1991 said

      I am not just starting and all that I know even handling files, now I am fully involved in the graphic part using perl qt4 and then go to the BD part and finally to the web part :), greetings and thanks for stopping by , and if with what you commented on c and c ++ it was a writing error, I got confused since those instructions work in both c and c ++ xD, correcting in the slides for exposition

      1.    axel brown said

        Hi Leonardo, can you give me a hand with this language? I need to run a perl from a php file, and I can't do it 😉 I hope you'll give me a hand, greetings!

  12.   alfonso said

    And is that archaic language still occupied?

    1.    Atheyus said

      If we talk about linux ...