Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Undefined Array Reference

by Nkuvu (Priest)
on Apr 22, 2009 at 23:40 UTC ( #759436=note: print w/replies, xml ) Need Help??

in reply to Undefined Array Reference

It took me a minute or three to figure out what the problem was. Correct me if I'm wrong: When you run the code, you get a "Can't use an undefined value as an ARRAY reference at line 21" error and you aren't sure why.

I can answer that part -- but what I can't answer is exactly what you're trying to do. The for loop is iterating from 0 to the maximum index in $ref_a. That reference is larger than what you'll find in $ref_b. Some simple print statement debugging will help show what I mean:

print "ref_a: ", $#$ref_a, "\nref_b: ", $#$ref_b, "\n"; for my $i (0..$#$ref_a) { print "Reading element $i\n"; push @{$ref_a->[$i]}, @{$ref_b->[$i]}; }

With some output:

ref_a: 5 ref_b: 2 Reading element 0 Reading element 1 Reading element 2 Reading element 3 Can't use an undefined value as an ARRAY reference at li +ne 23

To correct this problem, you can just choose the minimum of the two ref_a/b indices. But since I don't know what your goal is, I don't know if this will correct your issue.

Replies are listed 'Best First'.
Re^2: Undefined Array Reference
by Anonymous Monk on Apr 23, 2009 at 03:50 UTC
    The reason for that is a query result from a database, each array ref, since I can not join these tables, are each from these tables, and I don't know how many records each one will be returning, that is the reason for this sample code.
      I'd really like to know why you can't join the tables...
        The tables are too big, they are already a logic file from 3 different tables each. Thats the only way, I have to get the values from the first and after finding the account numbers I can get the rest from the other table, manipulate the results in the array ref and format a report

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://759436]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-10-19 02:40 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (251 votes). Check out past polls.