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.

Neil Watson
watson-wilson.ca


In reply to Return a hashref into another by neilwatson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.