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
You could also do away with $datamodels entirely, but the order of the output would be random.foreach my $datamodel (@$datamodels) { my $file = $filenames->{$datamodel}; print "$file\n"; }
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
In reply to Re: Returning and passing references to hashes
by ikegami
in thread Returning and passing references to hashes
by mnlight
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |