Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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]
[RonW]: choroba: Please define "high end" and "low end"
[LanX]: choroba: subversive (as usual ;)
[james28909]: i dunno, if i didnt have so little experience in linux i would swap. but it would be to much of a learning curve for me right now.
[choroba]: Low-end is defined as the Perl that generates millions of income
[choroba]: sorry, that's high-end, of coursse
[choroba]: low end, in my talk, will be code that "we don't touch because it works" and noone knows why
[choroba]: I want to present the most bizzare bugs and misfeatures I met when working for a large financial institution
[choroba]: I already gave a similar talk to my friends in a pub and at an internal conference at work and people liked it, so maybe...
[choroba]: LanX: That's the heritage, I can't do anything else
[RonW]: Sounds like some system my employer has "It does exactly what we need it to do and can't afford to risk anything we can't prove is 100% compatible"

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2017-05-22 21:35 GMT
Find Nodes?
    Voting Booth?