Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / What is perl???

Author
Message
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 6th Jun 2011 08:12
So... I've read articles that make perl sound like a standalone programming language, and I've read articles that make perl seem like something that patches together other applications (a big part of any programming language). One thing I just read was about "reversability" of code, or how easy it is to change (to suit another library). It said that if you had to integrate library calls with other code, then you could use definitions, and replace them with other sections of code, and then it somehow related this to perl (I'm looking, but can't find the exact quote, so I might be confused on what the article said >.>

So... What is perl, and why is it likened to a swiss army knife and duct tape?


Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
ionstream
20
Years of Service
User Offline
Joined: 4th Jul 2004
Location: Overweb
Posted: 6th Jun 2011 08:19
It's nothing special, it's just a general purpose programming language like Python. Like Python, the compiler and interpreter are one program (perl.exe or pl.exe), which means the code doesn't have to be compiled and run, just run. It has powerful built in string manipulation libraries along with networking libraries, so maybe that's why it's compared to a Swiss army knife.

Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 6th Jun 2011 09:58 Edited at: 6th Jun 2011 09:59
.. and it works on pretty much every platform there is. I used it a lot in an old job, and wrote a test infrastructure in it to run on every version of unix/linux (AIX,HP,Solaris,Red Hat etc), zOS, all versions of windows and more. I also built several websites in it using it's CGI library (infinitely better than PHP and a lot quicker than .NET). One program/script can execute anywhere. Plus as ionstream said, it has extremely powerful string manipulation and regular expression handling, plus highly condensed code.

The down side is, it's extreme flexibility means you can create code that is next to impossible to read if you don't consider maintenance. For example, it's possible to switch between object oriented and procedural code on the fly. Want to write procedurally? That's fine, but want to instantiate an object from an OO library? That's fine too. It can look hideous, and invariably when you get good at perl, you find yourself slipping into horrible habits.

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 6th Jun 2011 12:08
Hmm... So... where could I find an introductory tutorial on perl?

Also... is there any short snippet of code you could show me that... demonstrates some sort of usefulness? (Not implying it's useless at all xD)

if it's an alternative to PHP and useful for string manipulation, I'm in!

I really know nothing about using two coding languages on the same project, so that's probably what's confusing me. (I mean, save for HTML/PHP but...)


Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 6th Jun 2011 13:34
Ok, firstly, don't take learning Perl lightly. It's difficult, and has some concepts that take a while to get your head around. For example, variables:
$data is a scalar variable. ie. 1, or "Fred". It's weakly typed, so you can set $data to "bob" or 1 interchagably.

@data is an array. @ is always used to signify an array. If you want to pass an array to a function, you'd use @data, but if you want to reference an element in the array @data, you have to ask for a scalar, using $ ... so you end up going $data[3].

If I want to set a value in @data, I can go $data[1] = 'Bob', or I can go @data = ('bob'), and the reason is parenthesis () signify an array too.

Another weird example is if blocks. You can do if blocks in 4 different obvious ways, and there are more ... for example:
if ($name == 'bob') doSomething() else doSomethingElse();
doSomething() if ($name == 'bob') else doSomethingElse();
doSomething() ? ($name == 'bob') : doSomethingElse();
($name == 'bob' && doSomething()) || doSomethingElse();

There are lots of special variables and characters in perl. For example:
foreach (@myNames) {
print $_;
}

$_ is a reference to the last accessed variable. In this instance, it's each element in the array @myNames. There are loads of these, which makes reading perl quite tricky until you learn them.

Similarly, regular expressions are key to perl, but you can buy entire manuals dedicated to them. Easy example:
$data =~ s/foo/bar/g; (swaps all instances of 'foo' for 'bar' in string $data.).
$data =~ /.*(.)ABC/; (searches $data for the last instances of 'ABC' and then saves the character before 'ABC' into special perl variable $1, for you to reference later. (That's what the parenthesis (.) does in this instance.

I don't want to scare you, but that's the sort of stuff you have to be down with to get the most from perl!

So it ain't pretty at times, but the CGI library is really powerful and allows you to create really powerful websites, handles cookies for you, etc. Do complex manipulation of strings in single lines of code, deploy to any server on any OS and learn a language which is considered a powerful industry rarity.

Loads of help files here: http://www.perldoc.perl.org

Free perl should be downloaded from ActiveState http://www.activestate.com

Unfortunately, I don't have anything cool to show. Anything big I did is property of IBM (I left them a good few years ago) and I don't have any of it. I did start my own forum a while back thought (got some basic stuff working), so I'll check my laptop and if I can find it, I'll post it up.

Good luck if you decide to go down this road. If I ever code a dynamic website again, it'll be in Perl, no doubt, but it's tough to learn.

Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 6th Jun 2011 22:54 Edited at: 6th Jun 2011 22:54
Ah... I think I want to learn perl! I'll have to learn regex sooner or later. I don't particularly like the idea of having special variables like $_ and $1 though.

Quote: "doSomething() ? ($name == 'bob') : doSomethingElse();"

should this be
($name == 'bob') ? doSomething() : doSomethingElse();

?


Tell me if there's a broken link to images in a thread I post, and I'll fix 'em.
Plystire
22
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 6th Jun 2011 23:36
The way I read that line is the way the previous line was read:
Quote: "doSomething() if ($name == 'bob') else doSomethingElse();"


In that the block code is specified before the check. But, yeah, I'm used to doing the check first and the code after the '?', too since that's how it's done in other languages.


~Plystire

Only those who sow the seeds of their desires will reap their benefits later.
However, I have seeds of my own to tend to. I don't have time to be someone else's watering can.
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 6th Jun 2011 23:52 Edited at: 6th Jun 2011 23:56
Quote: "($name == 'bob') ? doSomething() : doSomethingElse();"


Yes, you're right. That's the beauty of perl. You always forget how it works and have to look at the docs time and time again.

Quote: "I don't particularly like the idea of having special variables like $_ and $1 though."


Yeah. To start with your good programming mind will steer you away from things like that, but eventually perl will corrupt you and you'll find yourself using them. $1 though is one you'll have to use if you want to extract data from complex regexps though, although no doubt there are 87 other ways to get the data out, so I'm probably wrong!

Login to post a reply

Server time is: 2025-05-21 11:44:24
Your offset time is: 2025-05-21 11:44:24