http://www.perlmonks.org?node_id=971684

gibsonca has asked for the wisdom of the Perl Monks concerning the following question:

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()