perlquestion
gibsonca
<p>
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.</p>
<p>Not a speed issue.</p>
<p>
The problem seems to be with the hash, after it has been passed back. </p>
<c>
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_stencil_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_mask'
printf("WriteCommand : cmd, addr, len = %d, %d, %d\n", $command, $address, $length);
printf("WriteCommand : pal info = %d, \n", $pal->{'palette_info'}[0]);
printf("WriteCommand : pal shade_stencil_mask = %d, \n", $pal->{'shade_stencil_mask'});
$pal->{'palette_info'}[0] = 444;
$pal->{'shade_stencil_mask'} = 234;
return($pal);
} # end of writeCmd()
</c>