Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Perl version usage

by aartist (Pilgrim)
on Dec 26, 2017 at 22:30 UTC ( [id://1206253]=perlquestion: print w/replies, xml ) Need Help??

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

We use Perl 5.10(Default version) or 5.18 (Locally Installed version) Is it ok to use ( I do not have a choice)? Which version do you use? What are the features of newer version of perl you cannot live without or make a good use of it? Thanks.

Replies are listed 'Best First'.
Re: Perl version usage
by kcott (Archbishop) on Dec 27, 2017 at 05:33 UTC

    G'day aartist,

    The Miscellaneous section of the online perldoc shows, amonst other things, all the deltas. Use this to determine new features (that are available in later versions) and changes to features (which are incompatible with, or require workarounds for, older versions).

    Perl 5.10.1 introduced changes which were incompatible with 5.10.0, so it's important to know which of those you're using. Perl 5.18.0 made a number of features experimental that previously weren't: workarounds are documented so you don't get masses of "experimental feature" warnings.

    The version you develop in should generally match the version used in production. You can write code in one version that will happily run in an earlier version; however, you'll need to be very aware of all the differences — if you don't have a solid familiarity with those differences, developing and running in the same version is probably the better choice.

    Beyond additional features, each new version will include bug fixes, optimisations, and so on: this is a good reason to use the latest stable version. Certain CPAN modules require particular versions: this could be a reason to upgrade. If you're using Unicode, you'll find newer Perl versions support more recent Unicode versions (I wrote a fair bit about that in "Re: printing Unicode works for some characters but not all").

    For my personal projects, I usually run the latest 5.x.0. If I see some major benefit introduced in 5.x.1, 5.x.2, or later, I'll upgrade; however, I don't do that very often. I'm currently running 5.26.0; I haven't upgraded to 5.26.1 which, at the time of writing, is the latest stable version.

    When I post code in response to questions on this site, I'll generally write code that should be able to be run with any version of Perl 5. When I include a feature introduced in a specific version, I make that very clear (and often provide a workaround for earlier versions).

    "Is it ok to use ( I do not have a choice)?"

    It's very unclear what you're actually asking here. What does "it" refer to? What do you mean by "ok"? What is the actual "choice" you've been given (or has been forced upon you)? How is that "choice" relevant in this context. If you can answer those questions, or rephrase your original question, I can probably provide a better answer.

    "What are the features of newer version of perl you cannot live without or make a good use of it?"

    I wouldn't say there are any features I can't live without; although, there are many features that I'll readily use where available (and, perhaps, be a little disappointed when they aren't). There's really too many to list. In "Perl 5.26.0 Available" I listed some of the features I particularly liked in that version.

    — Ken

      "Is it ok to use ( I do not have a choice)?"

      I wanted to state that.. As a Practical Perl Programmer, is it ok to practice with old-versions of Perl and not bother about new features?

      Thank you for the detailed answer.

        Thanks for the clarification. Unfortunately, I don't think there's a straightforward "Yes" or "No" answer to this.

        In a work situation, you'll often be required to code to a certain version, which could be a very old version. There can be many reasons for this, some are appallingly bad reasons; however, if you've agreed to take on a contract working with legacy code, then you're going to have to develop in an old version.

        In another work scenario, you may be required to upgrade old code to a more recent version. Now it becomes important to understand both the features of old and new versions.

        Even when working with older versions, you should aim to write your code such that it's easily converted to newer versions or, better still, requires no conversion. Just because the old version didn't pick up this classic syntax error:

        for my $item qw(item1 item2 item3) { # do something with $item here }

        does not mean you should include such an unreported error in new code written for an old version. See "perl5180delta: qw(...) can no longer be used as parentheses" if you're unfamiliar with that particular problem; be aware, that's just an isolated example of code that didn't follow the published syntax, but got away with it in earlier versions.

        As already indicated in my original response, I'll tend to avoid newer features in code I supply on this site. I'll generally aim to explain a technique using code that should work with whatever version of Perl the OP is using. If you're in a situation where you're mentoring, I'd recommend a similar approach; for example, use the well-known "@$aref" to initially explain a point, then introduce "$aref->@*" as a newer feature.

        For my personal code, I use a lot of the newest features; although, for anything that's not simply a "let's test this new syntax" script, I avoid experimental features. They will come back to bite you in the bum when their implementation is changed or, when deemed a failed experiment, removed completely. Don't use experimental features in production code.

        Anyway, there's a series of scenarios where "Yes", "No", "Maybe" or "Depends" could all be valid answers. You'll need to make separate judgement calls for each; based on context, requirements, in-house standards and so on.

        — Ken

Re: Perl version usage
by stevieb (Canon) on Dec 27, 2017 at 06:41 UTC

    I write code against all versions, but do my best to have said code run against everything down to 5.8 at minimum, and 5.6.x where possible. Sometimes I include libraries where they themselves require versions higher, but very infrequently.

    As an author more than a user, I 'use' every version that is visible to me that I can test against... Unix and Windows; I mean every version.

    No features inspire me, but I most definitely have read and understand every perldelta since the 5.6 days, and know what became available and when (of course, can't recall everything all the time ;)

    So, from my perspective, I code with 5.8 in mind, where possible.

    You? What made you ask this question?

      Thank you for the answer.

      What made you ask this question?

      I was checking if there is a new school of thought `how to use Perl`, keeping newer versions in mind.

        While I applaud stevieb's approach and might even consider it a best practice, holding oneself back to versions of Perl that were EOL'd a decade or more ago is akin to saying new versions of Perl do not matter. Moving from 5.6 to 5.26 is trivial compared to, say, moving from python 2 to 3. And if we're in a marketshare war, I argue expending effort to support old code is philanthropic but invisible.

        I think //= is, at this point, reasonable to expect. That means 5.10. I know there is a lot of 5.8 out there, I'm unhappily stuck on it at work but not for much longer. I don't personally feel the slightest responsibility on the cusp of 2018 to support it.

Re: Perl version usage
by siberia-man (Friar) on Dec 28, 2017 at 09:40 UTC
    As world said above, try to develop your scripts supporting even 5.8.x. From my practice... There were few cases when developing on Perl5.10/5.14 under Windows I released some scripts for Perl5.8 under Unix. I didn't use any modern features missing in 5.8. Simply trust me, everything was working fine under all the systems and versions.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1206253]
Approved by Athanasius
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-03-28 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found