This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 17
use strict hashpairs #281
Comments
rurban
added a commit
that referenced
this issue
May 14, 2017
Implements the new strict mode hashpairs, as described in #281. Catches wrong hash assignments at compile-time and run-time with rhs mapwhile, padav and rv2av. Also prepared use strict names (not on VMS), which is not checked yet.
rurban
added a commit
to rurban/Net-DNS
that referenced
this issue
May 14, 2017
All @algbyname arrays are already uppercased, skip the uc map there. See perl11/cperl#281 Also add the svn tags
rurban
added a commit
to rurban/distroprefs
that referenced
this issue
May 14, 2017
workaround strict hashpairs Starting with cperl 5.27 I disabled unpaired map processing to hashes unser use strict. See perl11/cperl#281 Therefore I rewrote the relevant dirty parts in the RR modules, and added a generic mapper Net::DNS::RR::_map_name() to unify the keys. It is also a bit faster.
Found and fixed CPAN problems:
|
rurban
added a commit
to rurban/Net-DNS
that referenced
this issue
Jun 1, 2017
All @algbyname arrays are already uppercased, skip the uc map there. See perl11/cperl#281 Also add the svn tags
rurban
added a commit
to rurban/perl-XML-LibXML
that referenced
this issue
Jan 9, 2018
fatal under use strict since v5.27.0c. See perl11/cperl#281 and http://perl11.org/blog/strict-hashpairs.html With map only a missing or a single pair is allowed to construct a hash, not multiple pairs.
rurban
added a commit
to rurban/perl-XML-LibXML
that referenced
this issue
Jan 9, 2018
fatal under use strict since v5.27.0c. See perl11/cperl#281 and http://perl11.org/blog/strict-hashpairs.html With map only a missing or a single pair is allowed to construct a hash, not multiple pairs.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
See #280.
For hash assignments we should restrict the mapwhile producer to accept only pairs, not arbitrary lists. Something like
use strict 'hashpairs'
.mapwhile will get a private OPp_MAP_HASH flag and warn with "Odd number of map elements in hash assignment". Implemented the warning with 8f9bc43
and the strict 'hashpairs' errror with fb247f2.
Producing lists:
-e'sub x{$,"ouch"};%h=map{$=>x}(0..3);while (($k,$v)=each %h){print "$k=>$v, "}'
=> 3=>ouch, ouch=>3, 1=>ouch, 2=>2, 0=>0 (5 keys!)
Similar: -e'%h=map{$=>(0,1)}(0..3);while (($k,$v)=each %h){print "$k=>$v, "}'
=> 1=>3, 2=>0, 0=>1 (only 3 keys, see below why).
Because -e'@h=map{$=>(0,1)}(0..3);print join" ",@h' => 0 0 1 1 0 1 2 0 1 3 0 1
-e'%h=map{$_}(0..3);while (($k,$v)=each %h){print "$k=>$v, "}'
=> 2=>3, 0=>1 (2 keys)
All but 0 and 2 elements could be ignored, and wrong (uneven) hash assignment needs to be warned with 'Odd number of elements in hash assignment'
Well, the last cases could be argued to be just
%hash = @array
splicing. The rhs list constructor should not care about the lhs hash.But with mapwhile, padav and rv2av on the rhs and a hash on the lhs of non-scalar assignments we do care now with warnings misc and strict hashpairs.
perl6 does not warn, it throws:
And there's also a
X::Pairup::OddNumber is Exception "Odd number of elements found for .pairup()
The text was updated successfully, but these errors were encountered: