my($dbh) = @_;
my @datamodels;
my %filenames;
my %dbids;
my $sql = "select DATAMODEL_CD, DB_ID, FILENAME from PRDRELEASE where RELEASE_FG = 1";
my $sth = $$dbh->prepare($sql)
or $app->error($FATAL, "Can't do SQL statement [ $sql ] :: $DBI::errstr");
$sth->execute();
while (my @values = $sth->fetchrow_array()){
push (@datamodels, $values[0]);
$dbids{$values[0]} = $values[1];
$filenames{$values[0]} = $values[2];
}#end while loop
printf("@datamodels\n");
my $numelements = @datamodels;
return (\@datamodels, $numelements, \%dbids, \%filenames);
my ($datamodels, $numelements, $dbids, $filenames) = get_data(\$dbh);
my ($dbh, $datamodel, $date, $numelements, $filenames) = @_;
my $file = "$filenames{$datamodel->[$count]}"
print "$file\n";
If you have hashrefs in scalar variables (as you do, e.g., $dbids), you can loop through the values like so:
for my $val (values %$dbids) {
# Do something with a value...
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:
[href://?node_id=383504#deref_syntax|Dereferencing Syntax]
[id://69927|References Quick Reference]
[id://137108|References Tutorial]
my $file = $filenames->{$datamodel};
this will work.perlmonks.org content © perlmonks.org and ikegami, mnlight, Roy Johnson
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03