#!/bin/perl -W # use strict; # my ( %Fruits ) = ( "Apples", 3, "Oranges", 6 ); &Print_Hash; # &Modify_Hash_1 ( \%Fruits ); &Print_Hash; # This doesn't seem to have any effect... # &Modify_Hash_2 ( \%Fruits ); &Print_Hash; # But this does... # sub Print_Hash { my ( $Fruit ); foreach $Fruit ( sort ( keys ( %Fruits ) ) ) { printf "\n%-7s: %d", $Fruit, $Fruits{$Fruit}; }; print "\n\n"; }; # sub Modify_Hash_1 { my ( $Ref_to_Hash ) = @_; $Ref_to_Hash = { "Pears", 5, "Peaches", 7 }; }; # sub Modify_Hash_2 { my ( $Ref_to_Hash ) = @_; my ( $Fruit ); foreach $Fruit ( keys ( %$Ref_to_Hash ) ) { delete ( $$Ref_to_Hash{$Fruit} ); }; $$Ref_to_Hash{"Pears"} = 5; $$Ref_to_Hash{"Peaches"} = 7; }; # # __END__