Stuck trying to pass an array that contains a hash to another subprogram

N

novak.dl

am modifying a Perl program and I'm stuck trying to pass an array
that contains a hash to another subprogram.

I have the following code (I will keep this as brief as possible
without leaving out any relevant pieces).

#Global Variables
my $new_decal_number = ' ';
my @citationpermit =();
my $cit_key = ();
....

main();

sub main
{
....
@citationpermit = prefix_citation_permits();

if ($counter > 0)
{
print("Number of citations to process: $counter \n");

###Cycle thru citations to update Citation_Main table
foreach $cit_key(@citationpermit) {
&updatecitation($cit_key);
....

sub prefix_citation_permits()
{
# statement handle
my @row = ();
my ($sth,@rows);
$sth=$dbh->prepare("SELECT cm.Citation_Key,
cm.Number,
cm.Decal_Number,
ISNULL(per.Last_Name, '
'),
ISNULL(per.First_Name, '
'),
....
while (@row=$sth->fetchrow_array ) {
$new_decal_number = ($permit_prefix_parm . '-' .
$row[2]);
print ("New Citation Decal Number: $new_decal_number
\n");
$counter += 1;
push @rows, {'citation_key' => $row[0],
'citation_number' => $row[1],
'decal_number' => $row[2],
'last_name' => $row[3],
'first_name' => $row[4],
'middle_name' => $row[5],
'local_id' => $row[6],
'new_decal_number'=> $new_decal_number};
}
return @rows;
}

sub updatecitation()
{
# statement handle
$rc1=0;
$rc2=0;


print("Old decal_number: $cit_key->{'decal_number'} \n");
print("New decal_number: $cit_key->{'new_decal_number'} \n");
....

Perl complains with the print("Old decal...) line with:
Use of uninitialized value in concatenation (.) or string at
permitprefix_test2.pl line 684.
Old decal_number:

It appears that it can't read the hash value in the updatecitation
subprogram. If I change the foreach to not run the subprogram
updatecitation and do the logic there, it works:

###Cycle thru citations to update Citation_Main table
foreach $cit_key(@citationpermit) {
# &updatecitation($cit_key);
print("Old decal_number: $cit_key->{'decal_number'} \n");
print("New decal_number: $cit_key->{'new_decal_number'} \n");
....

Can anyone assist me in how to pass the array of hashes to the
subprogram updatecitation?
 
D

Dave Weaver

sub prefix_citation_permits()
{
sub updatecitation()
{

In addition to Jim's comments, don't define your subs like that. The
empty parentheses are a prototype (see `perldoc perlsub`), telling
perl that the sub takes no parameters.

Define your subs like this:

sub updatecitation
{
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top