News for hackers. Stuff that matters.
Re:What’s new in Perl 5, Version 13 by wazoox on Tuesday September 28, 2010 @07:19AM (#1735286)
These are great enhancements!

Particularly, no $@ clobber, non destructive substitution, the news octal escape, the faster shift.

These I'm more doubtful :

New given/when return, why is that? new package block, why not... don't know if it's really worth it.

Anyway kudos for all the great work.

Re:What’s new in Perl 5, Version 13 by draegtun on Tuesday September 28, 2010 @08:51AM (#1735497)
New given/when return, why is that?

Allows DRYer code. So something like this:

    say do {
        if    ($grade eq 'A') { 'Well done!' }
        elsif ($grade eq 'B') { 'Try harder!' }
        elsif ($grade eq 'C') { 'You need help!!!' }
        else                  { 'You are just making it up!' }
    };
Could now be written this way:

    say do {
        given ($grade) {
            'Well done!'        when 'A';
            'Try harder!'       when 'B';
            'You need help!!!'  when 'C';
            default { 'You are just making it up!' }
        }
    };
Re:What’s new in Perl 5, Version 13 by thomas11 on Tuesday September 28, 2010 @09:23AM (#1735576)
But then, you could always use ternary tables:

    say do { ($grade eq 'A') ? 'Well done!'
           : ($grade eq 'B') ? 'Try harder!'
           : ($grade eq 'C') ? 'You need help!!!'
           :                   'You are just making it up!'};
I guess `given` with smart-match looks better when the implicit `~~` test is more complicated than `eq`.
Re:What’s new in Perl 5, Version 13 by draegtun on Tuesday September 28, 2010 @09:27AM (#1735590)
Yep but the given/when is DRYer because you don't need to repeat the $grade eq

re: smart match & more complicated than `eq` - Yes you can push given/when quite a bit:

    given (TheTime->of_day) {

        when ('morning') {
            breakfast();
            make_packed_lunch() if $_->is_work_day;
        }

        lunch() when 'afternoon';

        when ('evening') {
            goto_pub() if $_->is_friday;
            dinner();
        }

        default { say "Should be sleeping if its " . $_->{dt}->ymd }
    } 
ref: http://stackoverflow.com/questions/3638892/what-kind-of-neat...
Re:What’s new in Perl 5, Version 13 by wazoox on Tuesday September 28, 2010 @10:13AM (#1735727)
There are so many ways to shoot yourself in the foot with imbricated ternary tables that I don't even understand why you use them as an argument. It screams "don't do this!".
Re:What’s new in Perl 5, Version 13 by thomas11 on Wednesday September 29, 2010 @03:27AM (#1738598)
Well, I'd appreciate if you could elaborate on that. Ternary tables are in Conway's Best Practices, and while I certainly don't blindly follow any book, they have worked very well for many people, including myself. Compared to the if/else cascades of pre-5.10 Perl, they win hands down.
Re:What’s new in Perl 5, Version 13 by sigzero on Tuesday September 28, 2010 @07:31AM (#1735314)
The given/when replaces the kludge that is SWITCH I think. I like the new package block. I am not exactly sure why though. Thanks for the link.
Re:What’s new in Perl 5, Version 13 by draegtun on Tuesday September 28, 2010 @08:45AM (#1735473)
Yes given/when was added at perl 5.10 (2007) as the Perl6 style "alternative" to the Switch source filter kludge. Switch usage was deprecated and will now be removed from core with perl 5.13/5.14.