"=~" and "!~" operator makes odd hash count in Perl when passed in a subroutine

perl

Solution

The match operator in list context returns an empty list on failure. You could use

scalar( 'a' =~ /b/ )

or

'a' =~ /b/ ? 1 : 0

Problem

I am making a subroutine that accepts an array of hashes that have the same keys with different values. As a requirement, there are values that have conditional operations. sample: ``` use strict; use warnings; use Data::Dumper; sub test { my @data = @_; print Dumper(@data); } test( { 'value' => 1 == 2 }, { 'value2' => 4 == 4 } ); ``` output: ``` $VAR1 = { 'value' => '' }; $VAR2 = { 'value2' => 1 }; ``` but when I use `=~` or `!~` operators, the interpreter outputs this error: `Odd number of elements in anonymous hash at ...` ``` test( { 'value' => 1 == 2 }, { 'value2' => 'a' =~ /b/ } ); ``` output: ``` $VAR1 = { 'value' => '' }; $VAR2 = { 'value2' => undef }; ``` It seems that for false statements the hash value returns `undef` not `''`. I also tried putting undef directly on the hash value and it works ok. Question: - Why does perl outputs this behavior? - What is the best solution for this?

Original source