I don't want to make this hash 'palette' global, but rather pass it to a subroutine, have the hash updated, and then the result passed back, ideally 'palette' is now updated. This code is just my (last bad) guess at doing it.

Not a speed issue.

The problem seems to be with the hash, after it has been passed back.

use strict; use warnings; my $i; my %palette; $palette{'palette_info'}[0] = 128; $palette{'mask_info'}[0] = 0; $palette{'shade_stencil_mask'} = 99 ; my $data; ($data) = &writeCmd(111, \%palette, 222, 333); map { print "$_ => $$data{$_} \n" } keys %$data; # Problem starts after this point, how to update %palette %palette = %$data; # just my last guesss is here now # printf("main : data info = %d, \n", $palette->{'palette_info'}[0]); # printf("main : data shade_stencil_mask = %d, \n", $palette->{'shade +_stencil_mask'}); printf("main : data info = %d, \n", $data->{'palette_info'}[0]); printf("main : data shade_stencil_mask = %d, \n", $data->{'shade_ste +ncil_mask'}); exit(0); #****************** sub writeCmd() { #****************** # # my $command = shift; my $pal = shift; my $address = shift; my $length = shift; map { print "$_ => $$pal{$_} \n" } keys %$pal; # palette_info[0] mask_info'}[0] 'mask_info'}[0] 'shade_stencil_ma +sk' printf("WriteCommand : cmd, addr, len = %d, %d, %d\n", $command, $ad +dress, $length); printf("WriteCommand : pal info = %d, \n", $pal->{'palette_info'}[0] +); printf("WriteCommand : pal shade_stencil_mask = %d, \n", $pal->{'sha +de_stencil_mask'}); $pal->{'palette_info'}[0] = 444; $pal->{'shade_stencil_mask'} = 234; return($pal); } # end of writeCmd()

In reply to returning hash from sub problems by gibsonca

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.