UPDATENo need to reply to this one have found my mistake in the original code and rectified. Sorry to anyone who has spent time looking at this. I probably owe you all a trapist beer from The Abbey Leffe.

Thanks for all your help with my last dereferencing problem and sorry that my code was not very clear, I was working that day with a Leffe (Belgium Beer) hang over, I wasn't to sharpe. I belived that I had hashes and references clear until today when I tried the following.
I am working on testing some perl scripts, translated by someone else, which replace SCL main frame code on a new server. The scripts replicate the convention of a variable having a name, localname and default value. I have also xml files with data about the scripts from which I can extract the data I need to run my testing programs. I have come up with the following code.

sub make_var_hash{ my $xml = @_[0]; my %myhash; my $name; my $localname; my $defaultval; # #read the xml file extract the data and add to the following hash #UPDATE sorry this line should be $myhash{$name} = [$localname,$defaultval]; #NOT $myhash{$name} = ($localname,$defaultval); #end the loop return \%myhash; }
In my calling script
$hash1 = make_var_hash('MOR2305.xml'); foreach $key (keys($hash1)){ print "$key = $$hash1{$key}[0] & $$hash1{$key}[1]\n"; }
Works fine with the following result
START = MOR_START & 60 FINISH = MOR_FINISH & 150 etc....
Just what I needed!
However many of the scripts are strung together in suites and it would be useful to me to create a hash referencing the hashes created in in make_vars_hash.
So I tried this
sub get_suite_vars{ my %suite; my ($job_vars, $job); my @jobs = ('MOR2305.xml', 'MOP4312.xml', 'IN543.xml'); foreach $job ($job_vars){ $job_vars = make_var_hash($job); $suite{$job} = $job_vars; } return \$suite; }
However back in my calling script I started to get some starnge results and to stop a long story getting longer I changed above to.
sub get_suite_vars{ my %suite; my ($job_vars, $job); my @jobs = ('MOR2305.xml', 'MOP4312.xml', 'IN543.xml'); foreach $job ($jobs){ $job_vars = make_var_hash($job); #UPDATE for anyone interested the error was here #In my original code I had foreach $key($job_vars){ #SORRY foreach $key (keys($job_vars)){ print "$key = $$job_vars{$key}[0] & $$job_vars{$key}[1]\n"; } $suite{$job}=$job_vars; } return \$suite; }
Which produced
START = MOR_START & ARRAY(0x1930fo30) = & FINISH = MOR_FINISH & ARRAY(0x1931eaf0) = & etc....
Not what the doctor ordered. Whats happening? The code has been shortened a little but in principle is the same. Any help greatfully excepted.
Slight up date to inc. the file name in the first call to make_var_hash

In reply to More dereferencing by Scarborough

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.