Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Why should I use perl 5.10?

by saintmike (Vicar)
on Nov 30, 2007 at 04:49 UTC ( #654042=perlquestion: print w/ replies, xml ) Need Help??
saintmike has asked for the wisdom of the Perl Monks concerning the following question:

So, we all know that perl 5.10 is just around the corner and know what the changes were, because we can read perldelta.

I'm interested in something else: Give me a snazzy marketing pitch on why 5.10 is better than 5.8, from the perspective of the end user.

We'll be back right after these messages.

Comment on Why should I use perl 5.10?
Re: Why should I use perl 5.10?
by Prof Vince (Friar) on Nov 30, 2007 at 07:59 UTC
    It's a seamless and logical update from 5.8. Why would there be a need for any marketing besides this ?

      Plus 5.10 is faster, smaller, and cooler. What more do you need? O yeah, how about switch/case statement and named captures in regexp as a couple of bonuses, among many others? Those are features many Perl programmers have been waiting for ages, and finally their wishes have been fulfilled.

      All you need to do is upgrade your OS distribution or install a fresh box in a few months, and Perl 5.10 will most probably be there, ready for use.

      You can just use 5.10 as if it were your old 5.8. Discover new cool features as you go, at your pace. Really, there's NO risk.

        Faster? Anyone got some numbers to prove this?
Re: Why should I use perl 5.10?
by chromatic (Archbishop) on Nov 30, 2007 at 08:16 UTC

    You won't get bugfixes or support on p5p for 5.8 anymore, except at the syntax level.

Re: Why should I use perl 5.10?
by fenLisesi (Priest) on Nov 30, 2007 at 08:19 UTC
Re: Why should I use perl 5.10?
by ForgotPasswordAgain (Deacon) on Nov 30, 2007 at 09:15 UTC
    It will make attractive people want to have sex with you because of how rich you'll become.
Re: Why should I use perl 5.10?
by mwah (Hermit) on Nov 30, 2007 at 09:28 UTC
    Give me a snazzy marketing pitch on why 5.10 is better than 5.8, from the perspective of the end user.

    It has: Named Captures!

    The long wait is over ;-)

    regards

    mwa

Re: Why should I use perl 5.10?
by moritz (Cardinal) on Nov 30, 2007 at 10:09 UTC
    Well, it has the say builtin. And say $foo; is so much shorter and sweeter than print $foo, "\n";.

    Admitted, doesn't sound really great, but try it! After writing a few scripts in Perl 6 I wouldn't want to miss it.

      Well, it has the say builtin.

      and

      Admitted, doesn't sound really great,

      this is exactly my opinion too, say() doesn't say anything about its use ;-)

      Wouldn't even println() have been a better naming choice? (BYMMV) ;-)

      ... { local $\ = "\n"; ... ... print $foo; ... }

      Regards

      mwa

        Wouldn't even println() have been a better naming choice?

        Surely not!

        Perl builtins tend to be one word that can (syntactically) be read as plain English, with a few exceptions that come from POSIX system calls (like gethostbyname)

        And println is too long, compared to say ;-)

        The word say suggests some I/O similar to print, which in fact it is. The exact semantics are not obvious, but they aren't hard to learn.

        I don't understand why we didn't just use puts(). NIH?

Re: Why should I use perl 5.10?
by grinder (Bishop) on Nov 30, 2007 at 11:35 UTC

    Here are some things of the top of my head that I think are pretty cool:

    • state variables No more scoping variables with an outer curly block, or the naughty my $f if 0 trick (the latter is now a syntax error).
    • defined-or No more $x = defined $y ? $y : $z, you may write $x = $y // $z instead.
    • regexp improvements Lots of work done by dave_the_m to clean up the internals, which paved the way for demerphq to add all sorts of new cool stuff.
    • smaller variable footprints Nicholas Clark worked on the implementations of SVs, AVs, HVs and other data structures to reduce their size to a point that happens to hit a sweet spot on 32-bit architectures
    • smaller constant sub footprints Nicholas Clark reduced the size of constant subs (like use constant FOO => 2). The result when loading a module like POSIX is significant.
    • stacked filetests you can now say if  (-e -f -x $file). Perl 6 was supposed to allow this, but they moved in a different direction. Oh well.
    • lexical $_ allows you to nest $_ (without using local).
    • _ prototype you can now declare a sub with prototype _. If called with no arguments, gets fed with $_ (allows you to replace builtins more cleanly).
    • x operator on a list you can now say my @arr = qw(x y z) x 4. (Update: this feature was backported to the 5.8 codebase after having been implemented in blead, which is how Somni notices that it is available in 5.8.8).
    • switch a true switch/given construct, inspired by Perl 6
    • smart match operator (~~) to go with the switch
    • closure improvements dave_the_m thoroughly revamped the closure handling code to fix a number of buggy behaviours and memory leaks.
    • faster Unicode lc, uc and /i are faster on Unicode strings. Improvements to the UTF-8 cache.
    • improved sorts inplace sorts performed when possible, rather than using a temporary. Sort functions can be called recursively: you can sort a tree
    • map in void context is no longer evil. Only morally.
    • less opcodes used in the creation of anonymous lists and hashes. Faster pussycat!
    • tainting improvements More things that could be tainted are marked as such (such as sprintf formats)
    • $# and $* removed Less action at a distance
    • perlcc and JPL removed These things were just bug magnets, and no-one cared enough about them.

    update: ok, in some ways that's just a rehash of perldelta, here's the executive summary:

    There has been an awful lot of refactoring done under the hood. Andy "petdance" Lester added const to just about everything that it was possible to do, and in the process uncovered lots of questionable practices in the code. Similarly, Nicholas Clark and Dave Mitchell nailed down many, many, many memory leaks.

    Much of the work done to the internals results in a much more robust engine. Far likelier err, less likely, to leak, or, heavens forbid, dump core. If you have long running processes that chew through datasets and/or use closures heavily, that is a good reason to upgrade.

    For new developments, there are a number of additions at the syntax level that make writing Perlish code even better. Things like Mark-Jason Dominus's book on Higher Order Perl makes heavy use of constructs such as closures that tend to leak in 5.8. If this style of programming becomes more widespread (and I hope it does, because it allows one to leverage the power of the language in extraordinary ways) then 5.10 will be a better fit.

    Years ago, having been bitten by nasty things in 5.6, I asked Does 5.8.0 suck?. As it turns out, it didn't. I think that 5.10 won't suck, either. One big thing that has changed then is that far more people are smoking all sorts of weird combinations of build configurations on a number of different platforms, and many corrections are being made as a result of that. Things that otherwise would have forced a 5.10.1 to be pushed out in short order.

    update: clarified the "no more foo" additions, as per dmorgo's comment.

    • another intruder with the mooring in the heart of the Perl

      Really, that's an excellent summary, much more readable than the perl5 delta.

      I hadn't realized that unicode handling had been sped up a bit: that sounds like one of the more practical advantages. I know at least one place that's still running on 5.6 perl because they saw a 30% slowdown in their attempt at upgrading to perl 5.8 (they didn't know about "use bytes", but cut them some slack, that's an easy thing to miss).

      My personal favorite new feature would be the improvements to the regular expressions: it's now possible to do recursive regexps in a much neater way than the experimental features in 5.8 (no, I don't actually have a use for this, but I still think it's really neat...).

      Finally a real switch statement! BTW, that is the best summary I've seen so far.

      My understanding is that most of these new features need to be enabled with use, if so, I'm assuming it will be easier to add new syntax features in the future?

      -Lee
      "To be civilized is to deny one's nature."
      x operator on a list you can now say my @arr = qw(x y z) x 4

      THAT ONE IS DANGEROUS! The current x operator provides scalar context to both its operands (@a = (1,2,3,3,3,3); print @a x 3; ==> 666), the new one will not. While this may seem unimportant since it's unlikely that you'd want to repeat several times the lenght of an array it may easily cause problems with things like foo(...) x 8. Suddenly the foo() will be evaluated in a different context! That might easily lead to hard to find bugs!

      Update: Looks like the change is more restricted than I thought so it should not be a problem. Thanks Somni!

        This change applies specifically to qw(...). The code:

        @x = qw(a b c); print @x x 3;
        still prints "333". qw(a b c) x 3 used to be a syntax error.

        What I find confusing is why this is mentioned for 5.10. This was added in 5.8.8 according to my perl588delta.

        The qw() operator provides list context already. So
        print ( qw(a b c) x 3 );

        yields the same result as

        @l = qw(a b c); print ( (@l) x 3);

        which makes sense imho. An array isn't a list, but a qw() expression is.

        update: as a reminder, this is from perlop:

        Binary "x" is the repetition operator. In scalar context or if the left operand is not enclosed in parentheses, it returns a string consisting of the left operand repeated the number of times specified by the right operand. In list context, if the left operand is enclosed in parentheses or is a list formed by "qw/STRING/", it repeats the list. If the right operand is zero or negative, it returns an empty string or an empty list, depending on the context.

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      When you say "no more <insert foo syntax here>" do you mean these things are no longer supported, as in, existing code will break?

      That's kind of what it sounds like you're saying. However, I think it's not what you mean.

      While the intended meaning may be obvious to me and to most of us, there are a lot of redditors here today reading this, some of whom are going to think "holy crap, Perl sure breaks a lot of stuff when it moves forward in a dot release." Maybe a bit of clarification would be nice on what breaks and what doesn't.

      Thanks for the great post! I'm looking forward to using these features.

      • state variables No more scoping variables with an outer curly block, or the naughty my $f if 0 trick (the latter is now a syntax error).
      I think you mean "static variables". A state variable is, generally, just a global variable, typically those used by the system, for example all those variables (with a special name) in perlvar.

        I think the OP means "state variables" as that's what they are called in Perl 6. The declarator is the word state too.

        sub foo { state $x = 0; # $x will retain it's state through # successive invocations of foo() # ... }
        (Yes, other languages use the keyword static, but this is Perl!)
      Thanks for the catalog. I've been focused on Perl 6, and had no idea that 5.10 back-ported so many important features. I also noticed 'say' as a built-in.

      Re stacked filetests: The syntax is different, but you can indeed stack them. And define your own operators on your own types that work the same way.

        The article says: "defined-or No more $x = defined $y ? $y : $z, you may write $x = $y // $z instead." Does "no more" in this case mean you are no longer *allowed* to do it, or you no longer *need* to do it, because there is an easier way? I must assume the latter!
Re: Why should I use perl 5.10?
by xdg (Monsignor) on Nov 30, 2007 at 12:35 UTC
    • Newer versions of core modules that fix many bugs, particularly with respect to MSWin32.

      Yes, you can get these on CPAN for 5.8.8, but for @jobs that insist on only using core modules, Perl is getting a lot more friendly to MSWin32.

    • Module::Build in core

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      Yes, you can get these on CPAN for 5.8.8, but for @jobs that insist on only using core modules

      I have encountered @jobs with just that restriction. Any libre/open software that is not explicitly indemnified by the vendor must be individually approved (along with any dependencies) for the specific version and license.

      Perl itself may be an approved product, but non-core modules must go through the same process as any other non-vendor provided resource. Perl 5.10 will not change that aspect of those @jobs, but getting the 5.10 release of Perl approved will be easier than the multitude of individual module updates.

        Could you have, like, approved Debian etch, and then install all the perl modules from deb packages?

Re: Why should I use perl 5.10?
by dragonchild (Archbishop) on Nov 30, 2007 at 13:38 UTC
    Because you want to use something that it provides that 5.8 doesn't. Otherwise, upgrading for the sake of upgrading is stupid and foolhardy and shouldn't be done.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: Why should I use perl 5.10?
by dk (Chaplain) on Nov 30, 2007 at 19:58 UTC
    No, I think you shouldn't use perl 5.10. Why should anyone give you a snazzy marketing pitch? Are we on a market, selling ?

    (--me if you like but I won't write unpleasant responses as anonymous)

      Are we on a market, selling ?

      Yes, absolutely yes. Why do people work on open source projects if not to have people use them? Even if you don't contribute directly to the project, the network effects of the project mean that you'll get more value from a software project as the number of people using it increases.

      Marketing is absolutely not a dirty word.

      xoxo,
      Andy

        That's your view on things, through a prism of marketing. I respect that, but I personally do not want to look at my own hobby that way. Because if I adopt that point of view, I also should adopt all the necessity of snazzy marketing pitches, principles of monetary reciprocation, and god forbid, market diversification strategies. So, to put it simply, I personally do not sell anything.
Re: Why should I use perl 5.10?
by redhotpenguin (Deacon) on Nov 30, 2007 at 20:24 UTC

    The regex engine uses trie data structures when dealing with alternations (foo|biz|bar). So if you have massive regular expressions that make heavy use of alternation (like I do), you should see a performance boost.

    A trie is a very cool data structure, quoting wikipedia "The worst-case lookup speed in an imperfect hash table is O(N) time, but far more typically is O(1), with O(m) time spent evaluating the hash." I can't do the explanation justice so go read it for yourself, it is a worthwhile learning experience.

Re: Why should I use perl 5.10?
by Anonymous Monk on Dec 01, 2007 at 02:34 UTC
    Because if you upgrade TODAY, we'll not only give you the shiny new 5.10 but also throw in a couple of new modules like the very jazzy CPANPLUS, all for free! Heck, even take everything without paying a single dime! So, what are you waiting for? Pick up that phone and dial 555-....
Re: Why should I use perl 5.10?
by ikegami (Pope) on Dec 01, 2007 at 03:33 UTC

    What should you use 5.10 ...for what?

    Coding?
    - You get to use many improvements in projects that don't require backwards compatibility.
    - You get to familiarize yourself with features you will eventually use yourself.
    - You get to familiarize yourself with features that will be discussed here and elsewhere.

    Testing?
    - You can find out if your modules work for people using 5.10.

    I had a few more reasons floating in my head, but they have escaped.

Re: Why should I use perl 5.10?
by ambrus (Abbot) on Dec 01, 2007 at 18:30 UTC
Re: Why should I use perl 5.10?
by syphilis (Canon) on Dec 02, 2007 at 13:34 UTC
    Give me a snazzy marketing pitch on why 5.10 is better than 5.8

    BTFOOM why anyone would want to downgrade from 5.8 to 5.1 :
    <sophism> C:\>perl -le "print $]; print $] < 5.8" 5.010000 1 </sophism>
    Cheers,
    Rob
      Using Perl 5.10 will reduce your electricity consumption by 10% and cut ur bill by 25%. Is this enough to motivate you to use Perl 5.10 ?

      I haven't upgraded yet, so...

      C:\>perl -le "print $]" 5.008008

      How can you feel when you're made of steel? I am made of steel. I am the Robot Tourist.
      Robot Tourist, by Ten Benson

Re: Why should I use perl 5.10?
by liverpole (Monsignor) on Apr 04, 2008 at 00:54 UTC
    I've been meaning to try Perl 5.10 for a while ... and I'm glad to say() that I finally have.

    The things I was mostly looking forward to were state, the builtin switch statement, the // operator and say.

    However, today I very happily discovered that Perl 5.10 eliminates my previously number one complaint about error messages.

    A colleague asked me today whether I knew of a way to find which variable was undefined in a line containing a string composed of many variables.  On the off-chance that this was better handled in 5.10 (which I hadn't yet read about), I tried a sample program in Perl 5.10, and was pleasantly surprised to find that:

    use strict; use warnings; my $a = 1; my $b = 1; my $c = 1; my $d; my $e = 1; my $f = 1; my $g = 1; my $h = 1; print "$a$b$c$d$e$f$g$h\n";

    Run this with Perl 5.8.0 and you get:

    Use of uninitialized value in concatenation (.) or string at x.pl line + 14. 1111111

    Whereas with Perl 5.10.0:

    Use of uninitialized value $d in concatenation (.) or string at x.pl l +ine 14. 1111111

    It's a minor textual difference, but a huge difference diagnostically!

    I'm very happy to upgrade to Perl 5.10!


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-12-20 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls