I couldn't quite get your code working the way you describe it. I may be missing some point in your program's process. However, assuming your data structure is a hash of arrays (HoA) and you are trying to recover the values from the arrays. Here is what I came up with.
# Compiler directives and Includes use strict; use warnings; use diagnostics; # Global declarations; # Constants and pragmas use constant TRUE => scalar 1; use constant FALSE => scalar 0; ###########################################################; #main() { my $value1 = 0; my $value2 = 0; my $ref = RtnRef(); my $key = ''; # this line will rtn both the key and the value from the hash # foreach $key (%$ref){ foreach $key (keys %$ref){ # this works # ($value1, $value2)= @$ref{$key} # @$ref{$key} rtns array ref ($value1, $value2)= @{$ref->{$key}} # rtns array vals ##do something... } #However when I pass the same $ref to a sub routine mysub($ref); exit; } #end main() ############################################################; sub mysub{ # my $param = (@_); # this rtns scalar @_ (== 1)) # my ($param) = (@_); # this works ($param = $ref) my $param = shift; # and so does this my $key = ''; my $value1 = 0; my $value2 = 0; # foreach $key (%$param){ foreach $key (keys %$param){ # ($value1, $value2)= @$param{$key} ($value1, $value2)= @{$param->{$key}} ##do something... } return; } ###########################################################; sub RtnRef{ my %myhash = (); my $key = 'key1'; $myhash{'key1'} = [23, 40]; $myhash{'key2'} = [01, 50]; $myhash{'key3'} = [99, 22]; return \%myhash; } ############################################################;

In reply to Re: A dereferencing problem by periapt
in thread A dereferencing problem 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.