rheaton has asked for the wisdom of the Perl Monks concerning the following question:

Ok, first some background.

@tfl_list contains a unique list of tables. @tfl_file contains multiple lines of Data to be processed in a 2 Dimensional Array.

I am able to Reference and Print the Data from the 2 Dimensional array outside of the foreach $target_table (@tfl_list) loop.

For each of the "$target_table"'s I need to check a field in the Data Array and if that Field is the same as the $target_table then "Do Something". The problem with the code below is that when trying to de-reference the tfl_line Array nothing is returned. What am I doing wrong? I am sure this is something simple I am forgeting. Thanks

foreach $target_table (@tfl_list) { print "Target Table = $target_table\n"; foreach $tfl_line (@tfl_file) { print " Ref Table = $tfl_line->[9]"; if ($target_table eq $tfl_line->[9]){ #Do Something } } }

Replies are listed 'Best First'.
Re: Accessing multiple Arrays and
by alpha (Scribe) on Dec 28, 2006 at 17:56 UTC
Re: Accessing multiple Arrays and
by gaal (Parson) on Dec 28, 2006 at 17:57 UTC
    First, are you running under strict and warnings? This may be helpful.

    Putting a print of @tfl_line right after the foreach can help too. Are you sure it's slot 9? It's easy to make a mistake when the array has several elements. In particular, slot 9 is the 10th one, because arrays start with 0. I don't know much about your data but maybe @tfl_file can be an array of hashes instead of a 2d array?

      I am sure about slot 9 I can print it if I simply remove the "foreach $target_table (@tfl_list)" loop.
        So what is the exact error you're getting? Empty $tfl_line->[9] ? Or the "#Do Something" is never executed ?
Re: Accessing multiple Arrays and
by geekphilosopher (Friar) on Dec 28, 2006 at 17:57 UTC
    What do you mean by "nothing is returned"? Do you get a print out saying "Ref Table = something"? A Data::Dump of @tfl_list and @tfl_file would make this problem easier to solve - right now, I'm not sure exactly what those data structures look like, so it's hard to tell what's going on.
      Empty String seems to be returned. When I print it nothing appears so I assume it to be empty string.
        print "  Ref Table = $tfl_line->[9]"; should be print "  Ref Table = ".$tfl_line->[9];