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

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

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

    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?
    , Mar 21, 2007
    #1
    1. Advertising

  2. Dave Weaver Guest

    On 21 Mar 2007 15:54:41 -0700, <> wrote:
    >
    > 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
    {
    ...
    Dave Weaver, Mar 26, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Jones

    Hiding of subprogram designators

    David Jones, Nov 17, 2003, in forum: VHDL
    Replies:
    1
    Views:
    547
    Alan Fitch
    Nov 18, 2003
  2. Taras_96
    Replies:
    2
    Views:
    4,853
    Taras_96
    Aug 3, 2005
  3. rp
    Replies:
    1
    Views:
    494
    red floyd
    Nov 10, 2011
  4. Srijayanth Sridhar
    Replies:
    19
    Views:
    596
    David A. Black
    Jul 2, 2008
  5. kenneth
    Replies:
    1
    Views:
    115
    Gunnar Hjalmarsson
    Dec 11, 2004
Loading...

Share This Page