Greetings, I have this code where tests one and two fail. what does the error in line 18 mean in this instance and why are those hash keys destroyed?
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Data::Dumper;
my $master_ref = {
one => "first",
two => "second",
};
sub return_hash_ref {
return { three => "third", four => "forth" };
};
print "Before ".Dumper( $master_ref );
$master_ref = ( $master_ref, return_hash_ref() ); # line 18
print "After ".Dumper( $master_ref );
ok( $master_ref->{ one } eq 'first', 'one' );
ok( $master_ref->{ two } eq 'second', 'two' );
ok( $master_ref->{ three } eq 'third', 'three' );
ok( $master_ref->{ four } eq 'forth', 'four' );
done_testing;
Running it:
Useless use of private variable in void context at appendhashref.pl li
+ne 18.
Before $VAR1 = {
'two' => 'second',
'one' => 'first'
};
After $VAR1 = {
'four' => 'forth',
'three' => 'third'
};
Use of uninitialized value in string eq at appendhashref.pl line 21.
not ok 1 - one
# Failed test 'one'
# at appendhashref.pl line 21.
Use of uninitialized value in string eq at appendhashref.pl line 22.
not ok 2 - two
# Failed test 'two'
# at appendhashref.pl line 22.
ok 3 - three
ok 4 - four
1..4
# Looks like you failed 2 tests of 4.