develooper Front page | perl.perl5.porters | Postings from September 2013

[perl #119667] smartmatch example in perlop is broken

Thread Next
From:
Father Chrysostomos via RT
Date:
September 8, 2013 13:57
Subject:
[perl #119667] smartmatch example in perlop is broken
Message ID:
rt-3.6.HEAD-1873-1378648626-1023.119667-15-0@perl.org
On Sun Sep 08 02:03:42 2013, mauke- wrote:
> perldoc perlop:
> 
> | or, if other non-required fields are allowed, use ARRAY ~~ HASH:
> |
> |     use v5.10.1;
> |     sub make_dogtag {
> |         state $REQUIRED_FIELDS = { name=>1, rank=>1, serial_num=>1
>    };
> |
> |         my ($class, $init_fields) = @_;
> |
> |         die "Must supply (at least) name, rank, and serial number"
> |             unless [keys %{$init_fields}] ~~ $REQUIRED_FIELDS;
> |
> |         ...
> |     }
> 
> But:
> 
> | ARRAY     HASH       any ARRAY elements exist as HASH keys
> |                like: grep { exists HASH->{$_} } ARRAY
> 
> 
> So the make_dogtag example above doesn't check whether all of the
>    required
> fields (name, rank, serial_num) are present. Instead it checks whether
>    at least
> one of them is present (which is of course much less useful).

We’ve always had that problem.  Any non-trivial example of smartmatch
usually does something other than the author intended.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=119667

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