Greg Oliver wrote:
>
> Hi,
Hello,
> I am writing a script that initializes a %HoHoH while iterating
> through several items. This works correctly, and also retrieving
> the keys/values works correctly. I then call a subroutine that
> retrieves data and is SUPPOSED to update that same hash with the
> results. Unfortunately, when I get to the end of the program, the
> original data which I initialized it with is still there.
>
> I am quite sure it is probably a ref/deref problem, but have read
> every perlref/prelreftut example I could fine and no luck!
>
> Example:
>
> # Main
> my $Results;
>
> # Initialized with 3 for every value
> # $Results{ $cty }{ $dom }{ $eng } = "3";
>
> foreach my $cty ( @Cities ) {
> foreach my $dom ( @Domains ) {
> my @Engines = ( sort keys %Engine_Urls );
> foreach my $eng ( @Engines ) {
Or just:
foreach my $eng ( sort keys %Engine_Urls ) {
> $Results{ $cty }{ $dom }{ $eng } = "3";
> my @out = ( $cty, $dom, $eng );
> &SomeSub( \@out );
> }
> }
> }
>
> sub SomeSub {
> my ($refdata) = @_;
> my ($cty, $dom, $eng) = @{$refdata};
You are passing a reference to an array of three scalars and then
extracting the three scalars from the de-referenced array. Why not just
pass the three scalars?
> .....
> (modify some data)
> .....
> $Results{ $cty }{ $dom }{ $eng } = $newdata;
You should probably just return $newdata and assign it directly in the
foreach loop.
> }
foreach my $cty ( @Cities ) {
foreach my $dom ( @Domains ) {
foreach my $eng ( sort keys %Engine_Urls ) {
$Results{ $cty }{ $dom }{ $eng } = SomeSub( $cty, $dom, $eng
);
}
}
}
sub SomeSub {
my ($cty, $dom, $eng) = @_;
.....
(modify some data)
.....
return $newdata;
}
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]