Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I learn to write well-structured programs in Perl? [closed]

Tags:

perl

structure

I've started learning Perl but most of my former programming experience has been in languages that emphasize object oriented programming such as C# and Java. All the Perl examples I have found tend to be long single function programs and I find my self writing code the same way. Are there any resources or tutorials for writing maintainable well structured programs?

like image 747
Jared Avatar asked Jan 04 '09 03:01

Jared


People also ask

Is it worth learning Perl in 2022?

It is one of the oldest programming languages, but it is still one of the top-paying technologies. One might think that Perl is dead already, and there is no point in learning Perl, but if you have some Perl experience, you will still be in demand. Therefore, this programming language is worth learning in 2022.

Is Perl difficult to learn?

Is Perl difficult to learn? No, Perl is easy to start learning --and easy to keep learning. It looks like most programming languages you're likely to have experience with, so if you've ever written a C program, an awk script, a shell script, or even a BASIC program, you're already partway there.

Is Perl still used?

In 2020, it's easy to write off Perl as a language whose heyday has passed. But the reality is that, more than thirty years after its first release, Perl remains not only alive but still evolving (hello Perl 7!).

Who should learn Perl?

This Perl course is meant for students who have some basic knowledge of programming. If you have used another programming language before, terms like “arrays” and “regular expressions” will be more familiar to you. This course includes 14 hours of content and you can earn a certificate upon completion.


2 Answers

Firstly, regardless of what sort of Perl programming you're doing, you'll probably find Perl::Critic to be invaluable. The command-line tool is by far the most convenient for getting feedback on your code, but you there is also a web interface where you can upload your Perl code and receive instant, automated feedback. Note that Perl::Critic isn't going to teach you good structure, but it will help improve your style in general, and steer you away from some common mistakes.

To go with Perl::Critic, I'd recommend getting a copy of Perl Best Practices (PBP). It contains a lot of detailed information upon which Perl::Critic was based. Even if you disagree with particular guidelines in the book, it makes you think about how you code, and that's very, very valuable. You don't have to shell out money for a book, but the two compliment each other very nicely, and there are lengthy discussions you'll find in PBP that you won't get from Perl::Critic.

If you've already worked with other OO languages and OO design, the you'll probably find Moose to be a comfortable transition. Moose is very stable, very well supported, and has a huge and active community (especially via IRC). Moose supersedes almost all the existing OO Perl advice out there, including my own. Object Oriented design is common for a reason; it makes sense for a lot of projects, and there's no reason not to use it in Perl.

Personally, I found a massive improvement in my own program structure when I moved to a test-driven development model. Under such a model, breaking a problem down into small, easily tested units is essential. Start with Test::Tutorial if you're new to testing in Perl and then look at some other testing resources or books if you want to learn more. Use a tool like Devel::Cover or Devel::NYTProf to see what your test cases are hitting and what they're not. Having code that's hard to test is often a sign of poor structure.

Having said all this, the best teacher by far is to get involved with an existing Perl project with experienced contributors. See how they do things, and when you make contributions, think about their advice. If you want a real application with awesome cool value that seems to have sucked up the very best and brightest of the Perl community, then I'd recommend getting involved with Padre, the Perl editor.

If (for whatever reason) you can't get involved with another project, then consider posting code samples to communities such as Stack Overflow, or PerlMonks. Better still, if you can make your code open source, then do so, and solicit feedback. All programming languages are better learnt with others who are already familiar with them, and Perl is no exception here.

May you do Good Magic with Perl,

Paul

like image 194
pjf Avatar answered Nov 15 '22 03:11

pjf


Perl Best Practices

like image 44
Fhoxh Avatar answered Nov 15 '22 03:11

Fhoxh