Under use warnings; it gives a
Odd number of elements in hash assignment at ...
warning so define $SIG{ __WARN__ } to take some action.
Update: Here's a code example.
use strict; use warnings; $SIG{ __WARN__ } = sub { die q{Got a warning} }; my %hash = ( 'accents' => 'utf-8', 'accounting' => 'money', 'bank' => 'money'. 'ing' => 'money', 'perls' => 'perl', );
Update 2: Further updated code as per Camel Book, 4th edn. pp 1041 so as to get the actual warning message
use strict; use Carp qw{ carp croak confess cluck }; use warnings; $SIG{ __WARN__ } = sub { confess q{Got a warning: @_} }; my %hash = ( 'accents' => 'utf-8', 'accounting' => 'money', 'bank' => 'money'. 'ing' => 'money', 'perls' => 'perl', );
Output
Got a warning: @_ at xxxzzz line 5. main::__ANON__('Odd number of elements in hash assignment at x +xxzzz line 6.\x{a}') called at xxxzzz line 6
Update 3: The sub { confess q{Got a warning: @_} }; should of course have been sub { confess qq{Got a warning: @_} }; so that the @_ interpolates. The output then becomes
Got a warning: Odd number of elements in hash assignment at xxxzzz lin +e 6. at xxxzzz line 5. main::__ANON__('Odd number of elements in hash assignment at x +xxzzz line 6.\x{a}') called at xxxzzz line 6
Thus the perils of rushing to post before dashing out for an appointment :-/
Cheers,
JohnGG
In reply to Re: How to validate %hash = ( 'a' => 'b', ...);
by johngg
in thread How to validate %hash = ( 'a' => 'b', ...);
by RCH
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |