pritesh has asked for the wisdom of the Perl Monks concerning the following question:

Respected Monks,

I'm a Storage guy learning Perl for automation. I had written some scripts in the past, but even back then I could not find time to learn Perl every day.

With a new job, it's becoming difficult to find time to learn Perl everyday, and I have a nasty habit of quickly forgetting the syntax etc.

I find Perl scripting quite fun though and was wondering if you could suggest some ways to learn Perl effectively for someone who can only learn it sporadically.

Replies are listed 'Best First'.
Re: Help for a sporadical scripter.
by wjw (Priest) on Nov 04, 2014 at 20:04 UTC

    My learning environment over the years has been similar to yours. What I have found works well for me is:

    • I select a thing I want to learn and look here on PM for code with similar functionality, then modify it to suit my needs.
    • I keep a couple of folders with various functional Perl scripts, often named with rather long descriptive names so I can easily refer back to them.
    • I comment 'trial' scripts heavily and use git (locally) to find things I can't quite remember. Git also allows me to 'see what I learned last time' when it has been a while since a given script has been worked on
    • PerlBrew has been my friend!...for those times when examples just don't want to run on whatever version of Perl I am currently on
    • CPAN is darn handy for finding better ways of doing things.
    • Google or DuckDuckGo are indispensable for finding example Perl code
    • Spend time here going through the SOP's (old and new), just looking at the code and the comments, and occasionally offering something up just to see what criticism in might receive..

    Hope that might be helpful....

    ...the majority is always wrong, and always the last to know about it...

    Insanity: Doing the same thing over and over again and expecting different results...

    A solution is nothing more than a clearly stated problem...otherwise, the problem is not a problem, it is simply an inconvenient fact

      Hi wjw,

      Thanks for your suggestions. They are indeed quite helpful.

Re: Help for a sporadical scripter.
by tobyink (Canon) on Nov 04, 2014 at 20:36 UTC

    You only have limited time at work to learn Perl, but this needn't stop you learning it in your spare time.

    What things interest you? If you're a wine enthusiast, you could use Perl to create a database of your cellar contents, with a web-based interface allowing you to rate the wines you've tried.

    Or if you're interested in Sci-Fi, you could write an interactive Sci-Fi novel using Perl. (Like the Choose Your Own Adventure books, but with the added advantage of being able to store state.)

    Or maybe you're an amateur photographer, in which case you could try writing your own Flickr imitation.

    Come up with some kind of idea, and implement it. Write it as an open source project, so that other people can use it. You can learn from people's feedback, and from any patches they contribute back to you.

    Programming is not something you can learn entirely from reading. It's something you have to learn by doing.

      Programming is not something you can learn entirely from reading. It's something you have to learn by doing.

      I've never been able to learn anything without the doing part. Decades ago, I worked my way through an APL text expecting that a system supporting APL would soon be available. That system never materialized. The only thing I now retain regarding APL is the critical factoid that you need to buy a special golf ball for your Selectric in order to be able to write/print APL source code.

      In general, I've never been able to learn anything without being able to play with it, and the more play, the more learning.

Re: Help for a sporadical scripter.
by Laurent_R (Canon) on Nov 04, 2014 at 23:39 UTC
    When I first started to learn Perl about 11 years ago, I was part of an implementation team, dealing with data migration from a legacy system to a new system. The migration suite we were using was heavily written in Perl, so I thought I might as well try to learn the language to better understand it (I had been a developer and a development team leader for about 10 years before that, so, of course, I had a personal interest with programming).

    Anyway, I picked up a 70-page tutorial on the Internet (a fairly good one at the time, but outdated by today's standards), and read it over the course of two weeks on my free time (evenings and weekends, but not very intensely), also making small "baby Perl" test scripts.

    After these two weeks, it happened that something was getting wrong in our data migration tests and that we needed to reformat quite heavily some of the data files for the migration tests to succeed. As I was the most development-inclined member of the team, I offered to write a script the remedy the problem, and was thinking at the time to write it in Python, a language that I had been practicing for perhaps 3 to 4 years. Then, when I was going to write this thing, I suddenly thought: "Wait a minute, dude, you've just been trying to learn Perl, why not try to apply this new knowledge to this professional problem." So I tried.

    Because I felt that if would not be very fair to my employer to write my first real program in a new language on work time, I did this 300 or 400-line program over the next weekend. It turned out that it did not take me more time than what I was expecting to spend if I were doing in Python, a language that I knew much better at the time. It was fast enough (the data volume was very large), it worked well, and I loved the experience. In brief, I got converted to Perl. I no longer have the code of this program, I am sure that I would be today appalled by the coding quality (no use strict, using the -w flag instead of the better use warnings, poor command of many idiomatic shortcuts, bare-word file handles, limited knowledge of syntax for managing arrays and hashes, of course no idea about references and nested data structures, etc.) if I were to read it today. But it worked, it did what I meant, that was good enough.

    So I continued to use Perl (and dropped Python) for some personal uses and for professional uses, but not very intensely, remember I was in an implementation team, not a development team. But I continued to read other tutorials, bought over the months and years a few books (Learning Perl Programming Perl, Perl Pocket Reference, Perl Cookbook, etc.) and continued to slowly improve my command of the language.

    In 2010, I joined as a freelance consultant the technical team of a data quality department for a tier-one telecommunication operator (35 million mobile subscribers, about as many land-lines, Internet, TV, etc.). The main reason I was hired was that I had become over the previous 15 years a leading expert on both the functional aspects of the main mobile-phone customers rating and billing application used by this company, and technical expert of the proprietary programming language used by this application. My first task was to improve performance of many programs used on that application that were too slow, and did that quite successfully.

    When I became more knowledgeable of the specifics of that department, within about six months, I figured out that a number of the things we were doing in that team could most probably be done better in Perl. I started to do a few things in Perl and quickly convinced most of my colleagues of some of the advantages of using Perl (some of them had been using a bit of Perl, but only for quick one-liners within a shell script, or the like). In one case, I succeeded, by using Perl, to reduce by a factor of 100 the execution time of a program that was way too slow, that made the difference between a program that was just not usable (many days to execute) and a program that runs in an hour or two (perfectly acceptable for our work, given the huge masses of data we are manipulating).

    Ever since then, I am writing Perl code quite intensively, more than half of my time (unfortunately, being the expert on the other proprietary language mentioned before, I am spending still a good part of my time on it, but I have developed a strategy where I use it essentially to extract raw data from the database, and reprocess then the extracted files with Perl (this is the way I initially obtained the 100-fold performance improvement described above). I have become the Perl expert of the team, I wrote several relatively advanced modules for the benefits of the other team members, and I think I am truly an expert for the type of work we are doing (heavy data munging), even though I am definitely not one for many other uses of Perl (Web apps, graphical interfaces, network programming, using threads, OO programming, etc.).

    Just because this post might seem to lack modesty, I claim to have acquired a fairly good command of the core Perl syntax, including some relatively advanced topics, and to be an expert on some very specific uses of Perl (data munging), but I must clearly state that I know very little or close to nothing on many other aspects. Many many monks here have far more knowledge than I have, when I can give something, I do, but the important point is that I learn a lot everyday from reading PM (and a few other forums).

    All this long story to tell you how, despite that fact that development was definitely not my main activity when I picked up Perl, I was able at the time to do quite quickly very useful professional programs. And since I like the language, I constantly tried to (slowly, at the beginning) improve my knowledge of it, and I eventually became quite fluent with the basic syntax. Part of this has been made on my free time, but I certainly do not regret the personal investment. When I had the opportunity to use it more intensively, say early 2011, I quite easily and quite quickly convinced my colleagues of the advantages of Perl for the work we are doing.

    Today, I received a mail from a very young colleague (he is still an apprentice, spending about half of his time in university and the other half at workplace) in a remote location, the kind of person that would usually speak only about PHP, JS and Java, saying something like: "I think that this program is too complicated, I suggest that I rewrite it in Perl." It was so sweet to read that mail, I felt like I was eating a spoonful of honey.

    Finally, my point is this: if you are working in a high-tech profession (and if this is what you like), I think you sometimes also need to invest some of your own time into your training into new things. Your employer might pay you some training, and take it when you can. But you also need to do your homework, sometimes. Today (as very often in the last 18 months, part of my homework was spent on PM).

    OK, this is my vision as a pretty successful free-lance consultant, but I became that only because I invested some personal time into these things long before I became freelance. I am happy I did that, but it is up to you, I am not saying you should take a similar course of action. You might as well invest your time into other things, it is up to you. Having said all that, computing is not my only interest in life, I also practice photography, sailing and a few other things.

      Hi Laurent R,

      Thank you for taking time to write such a detailed post. Thank you for driving home the point that I need to invest more in learning. Your post is quite inspirational. I wish I could up vote it multiple times.

Re: Help for a sporadical scripter.
by davido (Cardinal) on Nov 05, 2014 at 04:22 UTC

    The Internet is full of fun little programming puzzles. Pick one puzzle every day. Arrive at work a half hour earlier than usual, fiddle with it for awhile, come back to it at lunch, finish it up before going home.

    For inspiration, see http://exercism.io/, https://projecteuler.net/, and so on.


    Dave

      Hi Davido,

      Thanks for the suggestions and the links.

Re: Help for a sporadical scripter.
by GotToBTru (Prior) on Nov 04, 2014 at 19:20 UTC

    I keep a Perl reference book on my desk. It is a bit dated, but it covers the basics.

    As I learn various tricks, I have been copying them to a text file I store on my desktop. I include both the code and an explanation. I try to review this file, top to bottom, every month or so. It has been a big help to memory.

    1 Peter 4:10

      Hi GotToBTrue,

      Thanks for the suggestion. I'll try that.

Re: Help for a sporadical scripter.
by PerlSufi (Friar) on Nov 04, 2014 at 19:40 UTC
    I would recommend Oreilly's 'Learning Perl'. It has exercises to go through for each chapter. It is what I started learning from.

      Hi PerlSufi,

      Thanks for the suggestion. I'm using Beginning Perl written by Curtis Ovid Poe. Planning to stick to it for a while. Of course, Learning Perl is an amazing book too. Just that I want to stick to this one and finish it out first.

        Ovid's book is also great. You can stick to it for a while without any problem. Except perhaps that it is sometimes (often) useful to also see the viewpoint of other authors to clarify some fine point that one author might have handled one way and another author some different way. But yes, Ovid's book is really great (and I am not saying that because Curtis "Ovid" Poe happens to be in the same Paris Perl Mongers group as me, I really believe it and I already thought so even before I met him for the first time a year or ago).
Re: Help for a sporadical scripter.
by Discipulus (Canon) on Nov 04, 2014 at 20:38 UTC
    My personal everytime suggestion is Perl Cookbook. Very suitable as occasional, sporadic reading: only recipes, problems and recipes. It is quite a bit old but the basics are well covered. If you also want to be up to date put on your desk also a copy of Modern Perl: review the basics you learned with the cookbook with a fresh look.

    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: Help for a sporadical scripter.
by soonix (Chancellor) on Nov 05, 2014 at 08:50 UTC

      Hi Soonix,

      Thank you for the cheat sheets. They're quite handy to have.

Re: Help for a sporadical scripter.
by pritesh (Scribe) on Nov 04, 2014 at 20:49 UTC

    Tobyink and Disciplus,

    Thank you for taking time to answer my question.