Showing posts with label Perl Handout. Show all posts
Showing posts with label Perl Handout. Show all posts

How to be a good Perl programmer

Now that we have learned a little about what Perl programming language is, let's tell you more about the art, the profession, or the hobby of programming in this wonderful language.

The Good Perl Programmer

It has a very famous slogan, which says that the good Perl programmer has three characteristics:

  1. It's lazy
  2. Impatient
  3. Hubris (in the sense of being arrogant)

Sounds like three bad things, doesn't it? But calm down, let's explain this story better.

A lazy person wants to do little work, try as little as possible.
So a good Perl programmer will try to do something, solve the problem as easily as possible, striving and rolling as little as possible to get rid of that problem right away.

There is even a famous phrase from Bill Gates that talks about it:

How to be a Good programmer

Impatient people don't want to do something the computer could be doing. After all, machines are for this: to do what we want, in a very quick way. So Perl programmers will avoid doing everything they can, and will delegate things to their scripts as much as possible.

You also have to be hubris. You have to want to share your code, show it to the community, to colleagues.

Obviously, you will not show an ugly, confusing script ... you will want to show something beautiful, simple, straightforward ... do in 10 lines what someone else did using 50.

Others also have to understand what you have done.
So you should also search in a readable, easily understandable way by others.
You have to want to show your work to others.

How to be a good Perl programmer

Another well-known phrase in the Perl world is:
There is more than one way to do it

It's such a flexible language that you'll never find two Perl scripts alike.
Perl programs are like a fingerprint, each one is different and is the face of its creator.

What will define you as a good programmer is your initial study here at Progressive Perl.
There is no right and wrong way to make code, there are ways and ways, so it is important here in the beginning to get you started, to make good code.

So for the rest of the course, read carefully, calmly, without haste.
Make sure you get everything right, it makes sense in your head.

Don't decorate, learn. It has to make sense, you have to understand what you are doing, what is happening and why.

Read here, do internet searches, visit forums, ask on social networks or here in the site comments. It is part of learning.

And the main thing: make the codes, write, type.
It's good to watch videos ... but just watching or reading will never make you a programmer.

Put your hand in the code, type, make mistakes, rewrite, that's how you learn.

By the way, it's important to persist.
Study. Did not understand? Read again. Nothing yet? Research, ask questions.

Going to do an exercise, can't you? Try again.
Nothing ? Try one more time.
At square zero? Go out, have a coffee, watch a youtube video, come back and try again.

A big, ugly, confusing code come out?
That's the way, little by little you get better.

Do you want to give up, do something else?
Relax your head, this is extremely normal, it happens to everyone.
The important thing is to go back to study, go back and try to solve the problem again.

Programming is that, solving problems, using creativity, programming is 99% transpiration and 1% inspiration.

Those guys who make wonderful code, in a few lines, without any mistake, did not reach that point overnight, no one is born knowing that.

It was sweating, grating, studying, trying again to make the script work, was reading code from others, asking, asking questions ...

OK?
Let's get our hands dirty?

Now, let's learn how to create our first Perl program in the next tutorial.

Printing Information on Screen: PRINT and SAY in Perl

In this Perl tutorial, we will learn how to display information on the command terminal using Perl's print and say functions.

Printing information on the command terminal

Printing, for us, is very reminiscent of making a print on a printer, right?
In fact, it is a broader term, means to display.

So when we talk about printing, we are simply showing some information, a text, a number or anything.

This is the first way we will learn about how to exchange information between the machine and the person using it. All commands and operations occur 'hidden' on your computer hardware, so we use some command that displays these results to us.

The most common ways of displaying information data are through the print and say functions in Perl, which simply show the information we want on the command terminal screen, let's learn how to use it?

print function in Perl

This function (command that does something specific) we already used in the tutorial on how to program the script Hello world! in Perl.

Just type the print command and type anything in double or single quotation marks and end the command with a semicolon;

Ready. What you typed in the quotation marks will appear on the screen.
These texts, in Perl, are called strings.

Test:
#!/usr/bin/perl
print "Progressive Perl tutorial";
The result will be:
Progressive Perl tutorial

But it got ugly, because it was 'pasted' with a command line text.

Line break character: \n

To solve this problem, just hit the enter symbol.
Enter symbol, in computing, is symbolized by: \n

Whenever Perl reads this command, it gives a jump, a line break.

Try it:
#!/usr/bin/perl
print "Progressive Perl tutorial \n";
The result is what we saw in the last tutorial, much cuter and more organized, isn't it?

And to display the result below:
Free, complete and online Perl tutorial

How would you program the Perl script?
You can do so much:
#!/usr/bin/perl
print "Welcome to: \n";
print "Progressive Perl \n";
Like all in one line, see:
#!/usr/bin/perl
print "Welcome to:\nProgressive Perl\n";

SAY function in Perl

Programmer is a lazy people. He likes to do everything as quickly, simply and economically as possible, the less work the better.

As if the print function was no longer simple enough, they invented the say function.

Change print by say and see the result:
#!/usr/bin/perl
use v5.010;
say "Progressive Perl tutorial";
Have you noticed?
It automatically gives the line break at the end, no need to use the line break \ n character.

Nice, isn't it?

PRINT exercises in Perl

1. Phrase on screen - Implement a program that writes the phrase "The first program we never forget!"

2. Etiquette - Design a program that writes your full name on the first line, your address on the second, and zip code and phone number on the third.

3. Lyrics - Make a program that displays on the screen a lyrics you like (forbidden lyrics by Justin Bieber).

4. Message - Write a message to a person you like. Implement a program that prints this message, prints it out, and sends it to this person. Say it was a virus that a hacker installed on your computer.

5. To the site - Make a program that shows on screen what you want to do using your Perl skills.

6. Square - Write a program that shows the following figure:

XXXXX
X   X
X   X
X   X
XXXXX

7. Gradebook - You were hired by a school to make the student report card system. As a first step, write a program that produces the following output:
Student          Grade
=========         =====
BRUCE              9.0  
STEVE              DEZ
DAVE               4.5    
NICKO              7.0

8. Large Letter - Design a program to produce the letter P of Progressive Perl. If it were ‘L’, would be like this:
L
L
L
LLLLL

9. Menu - Design a program that shows the following menu on the screen:
Customer base
0 - End
1 - Includes
2 - Alter
3 - Excludes
4 - Consultation
Option:

10. Pine - Implement a program that draws a "pine" on the screen, similar to the one below.

Enrich the design with other characters by simulating embellishments.
       X
      XXX
     XXXXX
    XXXXXXX
   XXXXXXXXX
  XXXXXXXXXXX
 XXXXXXXXXXXXX
XXXXXXXXXXXXXXX
       XX
       XX
      XXXX

Write your scripts in the comments!

The Perl Programming Language - What is it? What is it for? How it works?

In this initial tutorial of our free online Perl Course, we will tell you a little about the history of Perl, how it came about, for what purpose, what it really is, what it is for, where it is used, and other information.
How to program in Perl

Perl history

The Perl programming language was developed by a fellow named Larry Wall (a true internet legend) while working in a NASA lab. The first version was in late 1987. Therefore, it is a very mature language and still widely used, here to stay.

Perl was written in C language.

The initial purpose is curious, Perl was conceived as a kind of glue (Internet glue), to unite several tools of different languages ​​and different technologies, used by Larry and his colleagues. That is, Perl was born as a 'breaker' originally.

Although it was created decades ago, its development continues in full swing, always improving and evolving, with the help of thousands of people around the planet contributing freely and spontaneously, as it is completely free and free.

We will work here with the latest version, Perl 5.

The name Perl came from the initials:
Practical Extraction and Report Language

Why learn to program in Perl ?

There are a hundred programming languages out there, but why study and program in Perl?
What are the advantages? Worth it ?

First of all, we should make it clear that Perl is a very simple, straightforward language, quite easy to learn and absurdly flexible.

It focus is human understanding when it comes to creating the code. Unlike other languages, the focus is not on the machine, but on the programmer.

It is worth mentioning that it is completely free and free. Free to modify, distribute.

Perl is cross-platform, meaning that scripts run on both Unix systems (such as Linux), such as Mac and Windows, and the portability is quite interesting.

It is a language widely used to work with texts, through regular expressions (which we will study well in detail in the future), and the extraction of data and information is its strong point.

Where Perl is used ?

System and network administrators simply love Perl, he's a tremendous useful.
With very little code, you can manage a computer network in a very practical and simple way.

Perl is also widely used for CGI programming in the dynamic generation of web pages. There is Perl all over the hole and corner of the Internet, believe me.

Its focus, however, is the manipulation of data and information of various types, mainly textual. We'll see that with Perl you can do miraculous things, mess with millions of things with very little code and in a very easy way. This is very important when dealing with Linux files for example, or with Windows registries.

Computer Language and Programming

Before we go into detail in studying the Perl language, let's take a brush on some important subjects.
Throughout our Perl course, we will write code, which is nothing more than machine-specific commands to do what we want.

Obviously, it doesn't understand our language or Perl language.
As well?

You may have heard that computing is all 0 and 1, and indeed it is (actually it has to do with voltage). This is the only 'language' that the machine, the hardware understands.

So what we are going to do is write code that human understands (so-called source code) and use some little program to translate it into machine language, 0 and 1. This process, quite briefly, is compilation or interpretation, and usually results in an executable file such as the Windows .exe

When we do the compilation process, as in the C language, the compiler and other tools turn our source code into machine code, for her to understand. After that, just run the executable, once it was compiled and created, we don't need to repeat this process.

Already in interpreted languages, it is necessary that a program called interpreter always come to intercede for our blessed codes. In this type of process, perl (lower case p is a program) will interpret and run command by command of your script (coded text).