develooper Front page | perl.perl5.porters | Postings from December 2017

Re: Revisiting smart match

Thread Previous | Thread Next
From:
yary
Date:
December 29, 2017 22:01
Subject:
Re: Revisiting smart match
Message ID:
CAG2CFAb8UAgdoMm1L1iePQdLOiuehLhTFMo6uJBqxnaHmmNQiw@mail.gmail.com
Something to keep in mind in developing the smartmatch replacement is the
basic "switch-like" use of testing against literals.

As an example, excerpting code from
https://metacpan.org/source/CTBROWN/Date-Transform-0.11/Transform.pm lines
470+

given($r1) {

    when [ "T", "X" ] { $expansion = "%H:%M:%S"; }
    when "c" { $expansion = "%a %b %e %H:%M:%S %z %Y"; }
    when [ "C", "u" ] { $expansion = "%a %b %e %H:%M:%S %z %Y"; }
    when "g" { $expansion = "%a, %d %b %Y %H:%M:%S %z"; }

It's easy for humans to read and parse (and harkens back to the C-ish
origins of the switch statement which only allows constants)- keep "easy
things easy" going forward- thanks

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About