News for hackers. Stuff that matters.
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.