Advertising (This ad goes away for registered users. You can Login or Register)

[Tutorial] Introduction to Perl's awesomeness

Discuss about your favorite (gaming...or not) devices here. The most popular ones will end up getting their own categories
Programming discussions for your favorite Device
Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
Post Reply
User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

[Tutorial] Introduction to Perl's awesomeness

Post by m0skit0 » Fri Nov 18, 2011 7:52 am

<< Previous | Next >>
Introduction to the introduction

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
Perl scripts usually use .pl extension (although this is not necessary on UNIX systems).

So let's see our first Perl script: the honorable and mighty "Hello World".

Code: Select all

#!/usr/bin/perl

print("Hello world!\n");
We copy and paste this into a text editor and save it as helloworld.pl. To execute it, you can either invoke the perl interpreter with the script's path, like

Code: Select all

> perl helloworld.pl
or in UNIX systems you can mark the script as executable and run it like any other executable:

Code: Select all

> ./helloworld.pl
The first line (#!/usr/bin/perl) has no meaning in a Windows system and can be safely removed.

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
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

Sirius
Posts: 103
Joined: Sat Dec 18, 2010 3:31 pm

Re: [Tutorial] Introduction to Perl's awesomeness

Post by Sirius » Fri Nov 18, 2011 11:35 pm

awesome moskito, I will star learning it as soon as I finish my semester (2 weeks)
Advertising

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: [Tutorial] Introduction to Perl's awesomeness

Post by m0skit0 » Fri Nov 18, 2011 11:39 pm

Thank you. I'm sure you'll find it useful ;)
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

MVP
Posts: 78
Joined: Fri Jan 21, 2011 4:21 am

Re: [Tutorial] Introduction to Perl's awesomeness

Post by MVP » Thu Dec 15, 2011 8:03 am

hmmm im gonna have to check perl out, thanks for the intro.

User avatar
Acid_Snake
Retired Mod
Posts: 3099
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: [Tutorial] Introduction to Perl's awesomeness

Post by Acid_Snake » Fri May 25, 2012 12:54 pm

I find it really similar to python

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: [Tutorial] Introduction to Perl's awesomeness

Post by m0skit0 » Sat May 26, 2012 11:48 pm

You probably meant that Python is similar to Perl, not the opposite ;) Perl influenced a lot of popular modern programming languages like Python, PHP, Ruby or JavaScript. Well, it's not a surprise anyway ;)
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

User avatar
Acid_Snake
Retired Mod
Posts: 3099
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: [Tutorial] Introduction to Perl's awesomeness

Post by Acid_Snake » Wed May 30, 2012 3:23 pm

m0skit0 wrote:You probably meant that Python is similar to Perl, not the opposite ;) Perl influenced a lot of popular modern programming languages like Python, PHP, Ruby or JavaScript. Well, it's not a surprise anyway ;)
yeah I know, but since python is my first language I kinda "see" it the other way around, is like learning Spanish and then Latin

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: [Tutorial] Introduction to Perl's awesomeness

Post by m0skit0 » Wed May 30, 2012 3:49 pm

One must be able to put things chronologically taking away his own experience. This helps understanding a lot of things (e.g. why Python has some kind of features, or why Python was thought that way). If you only take into account your own experience, a lot of things will seem illogical.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

Post Reply

Return to “Programming and Security”