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:
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
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
Third Program: Basic Operations.pl
With the above learned we can now make a program that performs the four basic operations
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.
Oh! Ok, let's learn Perl 😀
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.
+5 And this Saturday you owe me a whiskey 😀
No drinks per mua ... if I drink whiskey it is able to put python in a symfony controller.
Yes, but I like Perl for handling files, and because it is oriented to scripts that help to schedule tasks on the server
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."
I also want to walk through Python and Ruby, but first I will finish at least the Perl xD Tutorial
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.
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.
Genie, will there be more of these installments, other languages like Python 3 or Ruby?
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
Thanks, I was looking for something like this.
Sorry, the one I put is not the introductory one, it's another one 😀
OH !!!! I save it for when I finish the Python course !!! 😀
Thanks Leonardo, I only ask you please if you can put the texts of the instructions instead of images 🙂
I forgot I already put the link with the codes in GitHub
Orale !!! I did not think it was so similar to C ++ !! , Excelent topic!!
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
I will take it into account, the formatting of the code leaves it as it is Sublime Text 🙂
Great contribution!
Congratulations!
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
The truth is very good and I will be looking forward to the next post, Greetings
It may be old-fashioned but it never hurts to know a little of this language ... thanks for this tuto ...
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.
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
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!
And is that archaic language still occupied?
If we talk about linux ...