- Introduction to the introduction/Installing the beast and launching our first awesome script
- Variables. Be strict with them!
- The arrays you've always dreamed of
- Script arguments/Water can flow... or it can crash!
Perl is mainly a scripting language. This means it's meant for small programs that automate some task. Perl also borrows a lot from UNIX culture and philosophy, since it was born around it. Perl also has a very flexible syntax, which lets the programmer choose how he wants to do the things and does not enforce him/her a way to do things (like most programming languages do). In this flexibility programming paradigms are also included. Perl won't enforce you to do OOP or imperative. It won't enforce functional. The programmer can choose any paradigm he likes, and Perl would be happy to make his/her wishes true. This syntax and paradigm flexibility allows faster programming, which is one of the main features wanted in a scripting language. I don't want to do "nice" programs, I just want short programs that do one simple (or not that simple) thing as fast as possible.
This flexibility, however, is one of the main reasons I would not recommend Perl as a first language. Perl is easy and does awesome manipulations with data, but it will introduce bad programming habits for a newcomer, and hide important concepts like pointers (which IMHO are basic to understand programming). I strongly suggest you using Perl only if you already have a good grasp of what good programming is, so you know that some stuff you're doing in Perl is actually bad programming in other circumstances (for example big software projects). Since in Perl you most likely won't be building big software (although this is definitely possible and done as well), most of the programming good practices can be ignored for the sake of doing things faster and shorter.
Installing the beast and launching our first awesome script
Before all: I won't be teaching how to install software on your OS. If you want to learn Perl you should at least know how to install software on your OS. If you don't, please start with simple things first like learning to use your OS.
For Linux users there's a very high probability Perl comes already installed with your distro. Perl is usually a standard inclusion on UNIX environments. This is because, as I stated before, Perl and UNIX have a love history. If not, use your repository tool as usual to search and install Perl. To install Perl additional libraries you can either use ActivePerl (like Windows users) or just use the very same repository tool.
For Windows users, I highly recommend ActivePerl over other choices like Strawberry Perl. Why this? Because of the Perl Package Manager bundled with ActivePerl. This tool will allow you to browse Perl's library repository and install/remove libraries with a GUI interface. If you end liking Perl, you'll just love the PPM.
Perl is an interpreted language. It does not generate binary executables (although this is possible) but rather executes the scripts as plain text. So Perl needs a Perl interpreter, which is what you have installed (along with a few libraries as well). For any OS, Perl interpreter can be invoked to execute a script like
Code: Select all
> perl perl_script_path
So let's see our first Perl script: the honorable and mighty "Hello World".
Code: Select all
#!/usr/bin/perl
print("Hello world!\n");
Code: Select all
> perl helloworld.pl
Code: Select all
> ./helloworld.pl
I think this simple script needs no explanation. Those already familiar with C will obviously notice the C-like syntax, which is just another proof of the strong UNIX-Perl tie. Perl's syntax is heavily influenced by C.
<< Previous | Next >>
Advertising