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

Discussion in 'Perl Misc' started by novak.dl, Mar 21, 2007.

  1. novak.dl

    novak.dl Guest

    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 = ();


    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) {

    sub prefix_citation_permits()
    # statement handle
    my @row = ();
    my ($sth,@rows);
    $sth=$dbh->prepare("SELECT cm.Citation_Key,
    ISNULL(per.Last_Name, '
    ISNULL(per.First_Name, '
    while (@row=$sth->fetchrow_array ) {
    $new_decal_number = ($permit_prefix_parm . '-' .
    print ("New Citation Decal Number: $new_decal_number
    $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

    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 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?
    novak.dl, Mar 21, 2007
    1. Advertisements

  2. novak.dl

    Dave Weaver Guest

    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
    Dave Weaver, Mar 26, 2007
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.