sub ReadSource( $ $ )
{
my $DataSource = shift;
my $HashRef = shift;
foreach my $ItemID (@Data)
{
my $data_array_ref = $HashRef->{$ItemID};
if ( $data_array_ref )
{
push( @{$data_array_ref}, $DataSource );
}
else
{
$HashRef->{$ItemID} = [ $DataSource ];
}
}
}
####
my %myhash = (); # empty hash
my @Data = ( 'this', 'that', 'that over there' );
my $datasource = 'banana';
ReadSource( $datasource, \%myhash );
##
##
use Data::Dumper;
ReadSource( $datasource, \%myhash );
print( Dumper( \%myhash ) . "\n" );
##
##
$VAR1 = {
'this' => [
'banana'
],
'that' => [
'banana'
],
'that over there' => [
'banana'
]
};