Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I work in Java so basically I use OOP paradigm during coding. I am about to start working in Perl and I was wondering what is the paradigm that Perl developers follow. In wiki it mentions that it supports many paradigms but I am not sure I understand this since it is a scripting language.

So my question is: Are the object oriented patterns I'm familiar with in Java idiomatic in Perl, or will I need significant change to my design style to write effective Perl?

Note: This is not a question to critique Perl. I actually have to work in Perl and would like to understand how the current way I program will change.

share|improve this question
On a more serious note, do a Google Search for "perl philosophy", and have a look here: perldesignpatterns.com –  Robert Harvey Mar 18 '13 at 18:15
Perl supports OOP. You can build class hierarchies implement virtual functions etc. Not the most common usage but it can be done. –  Loki Astari Mar 18 '13 at 20:12
add comment

3 Answers

Perl's philosophy tends to be that of "do what is practical now." If you need to use OOP, its there. It isn't necessary in all solutions and forcing a person to write OOP code when it is a simple "do this then this then this" type problem is often counter productive.

The multi-paradigm nature of perl can be seen in things such as the Schwartzian transformation which has very functional aspects to it (in Lisp it is known as "decorate-sort-undecorate"). OOP exists, as does procedural (C like programming) and imperative (bash like "do this then this").

Design Patterns are reoccurring solutions to common problems. They exist in every language. Sometimes these patterns are called idioms, though this may also refer to things that are much more simple than a pattern.

When necessary, many of the classic GOF Design Patterns can be implemented in perl. Perl Design Patterns will have many common names that people familiar with the GOF. It isn't necessary the case that all of them are idiomatic perl.

When exploring design patterns in perl, please also take note of "Design Patterns" Aren't by Mark Dominus.

Many consider that the Design Patterns are deficiencies in the language. In that perspective, Design Patterns such as the Iterator are often unnecessary in perl. Not always - but often.

First, write idiomatic perl. Don't try to write C in perl, or lisp in perl, or java in perl. Perl is perl. If there is a problem that gets bigger than idiomatic perl can handle and you start needing more complex class structures, then write them. Know the design patterns to be able to recognize "this problem has now grown to the point of needing an abstract factory" - but don't start out trying to make an abstract factory in perl if you don't need one.

Some libraries exist in both OOP and more traditional forms. See Should I use the function-oriented or object-oriented CGI interfaces? for an old SO question where one asks which way to use the library.

share|improve this answer
+1.Interesting information.Taking all these into account how come there are many posts in SO trying to defend/attack Perl as an old language?Seems powerful and useful to me. –  user10326 Mar 18 '13 at 19:30
Everyone has their own favorite language. Many feel that unless a language is able to support New Thing This Week, the language is old and out dated and everything should be moved from it. Others have significant time invested in learning a particular language and know how to make it work in the place where it is. This is easily changed to any language that doesn't move as fast as The Hot New Language. Perl suffers a particular disenfranchisement when the time it has taken to get Perl 6 (any day.. err.. year now!). This shouldn't deter one from learning perl - it is used in many places. –  MichaelT Mar 18 '13 at 19:36
You will likely find that perl is a lingua franca for linux scripting taking much of the role of shell scripting from the elder days. Only the most staunch shell scripters will complain if you write a perl script rather than bash when doing scripting on a *nix system. One of the most important things for perl is CPAN - if one is about to undertake writing some library of reasonable size, just check to see if someone else has already written it. –  MichaelT Mar 18 '13 at 20:25
Anything that used to be shell script of some complexity or greater is often a perl script now. Perl also often works as a glue/duct tape between systems or applications. Its string processing has also made it at home in several other industries (particularly bioinformatics - just go look at how many DNA based questions exist within the perl tag on SO). –  MichaelT Mar 18 '13 at 20:42
Perl is a robust and complete programming language. It can be used for scripting (automating interaction with other applications including the shell), or for building utilities, or even for larger scale applications. The Perl hatred tends to focus on things like its dense syntax, and to some degree, on a misunderstanding of the fact that Perl doesn't attempt to force specific design patterns on its users. I use Perl every day. I also use other languages frequently. I enjoy Perl's expressiveness and power. Get past the awkward learning stage and chances are you'll love it too. –  DavidO Mar 26 '13 at 15:18
show 2 more comments

Perl's stance on paradigms is TMTOWTDI (there's more than one way to do it). This is one of the reasons a lot of people jokingly call Perl a write-only language. It can be a lot easier to write it than read it, because another person's style may be completely different to yours.

That being said, OOP is certainly supported in Perl. If you're using a lot of third party code, it may or may not be OOP, but for your own code you can do OOP to your heart's content. I actually first learned OOP in Perl. I tried C++ first and it didn't "click" for some reason.

share|improve this answer
Why many people consider it is as a bad career option?It seems that it is powerful and can complement other languages as part of the toolset. –  user10326 Mar 18 '13 at 18:22
Let's just say other languages are almost as powerful and have a lot more inherent structure. Companies like structure. –  Karl Bielefeldt Mar 18 '13 at 18:29
For a good Perl OOP tutorial check codeproject.com/Articles/3152/Perl-Object-Oriented-Programming –  Pmarcoen Mar 19 '13 at 11:36
That is a good OOP tutorial, explaining Perl's in-built OO style. If you find that code a bit verbose, you may be interested in the Perl library Moose, which automates a lot of the repetitive coding in the in-built OO. But it's best to start (IMH0) with the in-built style. –  Disco 3 Mar 21 '13 at 9:57
I've never found Perl to be a bad career option. Find a local Perl Mongers group, and odds are that at nearly every meeting someone will mention Perl job openings. –  DavidO Mar 26 '13 at 15:21
add comment

I am in the same situation, I have been using Java for a looong time,

Having moved to Perl was a shock and a relief but, I used a book called 'Perl Best Practices' It helps a lot and if you understand the basic concepts of programming languages it's all easy to just flow with it.

Just remember with perl there is more then one way to do it, I have spend countless hours looking at certain code and modifying it, but in the end it gets the job done with a simple syntax error.

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.