in reply to Returning and passing references to hashes

You're treating "filenames" as a hash
$filenames{...}
instead of a reference to a hash
$filenames->{...}
or
${$filenames}{...}

In other words,
my $file = "$filenames{$datamodel->[$count]}";
should be
my $file = $filenames->{$datamodels->[$count]};
(What's with the quotes?)

Update: ... except that $count is undefined. Maybe you want

foreach my $datamodel (@$datamodels) { my $file = $filenames->{$datamodel}; print "$file\n"; }
You could also do away with $datamodels entirely, but the order of the output would be random.
foreach my $datamodel (keys %$filenames) { my $file = $filenames->{$datamodel}; print "$file\n"; }

I'd get rid of $numelements. There's no use for it.

Update: Some PerlMonks references on references:
Dereferencing Syntax
References Quick Reference
References Tutorial

Replies are listed 'Best First'.
Re^2: Returning and passing references to hashes
by mnlight (Scribe) on Jan 04, 2006 at 19:59 UTC
     my $file = $filenames->{$datamodel}; this will work.
    the quotes were just a mistake.
    Now that I can reference it this way I will get rid of numelements.
    I will keep those references in my favorites thank you.