in reply to Re^9: Can't use string as an ARRAY ref
in thread Can't use string as an ARRAY ref

No, that looks like a dump of $just_data. I wanted a dump of these ($princ, $type, $person) = get_person(); that are used to build $just_data.

poj

Replies are listed 'Best First'.
Re^11: Can't use string as an ARRAY ref
by Anonymous Monk on Aug 25, 2015 at 12:09 UTC
    Hi, these are the dump of ($princ, $type, $person) = get_person();
    $VAR1 = [ [ '12345', 'MONICA', '01/01/1900', '0X10' ], [ '000001', 'MARY L', '01/01/2000', '0111P' ], [ '8884', 'JOHN M.', '01/01/1932', '0OK8' ], ]; $VAR1 = [ [ 'Main', '1900', 'Red', ], [ 'APT', '1290', 'Blue', ], [ 'AVAL', '1921', 'Green', ], ]; $VAR1 = [ [ 'Q3.0', 'OK', '1900-01-01', 'N', 'O', 'O', 'X', 'Y' ], [ '12w', 'PL', '2000-01-02', 'N', 'P', 'O', 'X', 'A' ], ];

      In that case don't understand how this code works as I would expect the first column in each array to be a member number.

      foreach my $princ_row ( @{$princ} ) { my $member_number = shift @{ $princ_row }; push ( @{ $just_data->{$member_number}{princ} }, $princ_row); } foreach my $type_row ( @{$type} ) { my $member_number = shift @{ $type_row }; push ( @{ $just_data->{$member_number}{type} }, $type_row); } foreach my $person_row ( @{$person} ) { my $member_number = shift @{ $person_row }; push ( @{ $just_data->{$member_number}{person} }, $person_row); }

      It looks from the code that you are trying print a record from each array in a block of three tables where the lower 2 tables (type,person) are along side each other, is that correct ? The only way this will work is if each table contain only one record, is that correct ?


      poj
        Yes, and thats one my the problems. Like in this dump:
        $VAR1 = [ [ '12345', 'MONICA', '01/01/1900', '0X10' ], [ '000001', 'MARY L', '01/01/2000', '0111P' ], [ '8884', 'JOHN M.', '01/01/1932', '0OK8' ], ]; $VAR1 = [ [ 'Main', '1900', 'Red', ], [ 'APT', '1290', 'Blue', ], [ 'AVAL', '1921', 'Green', ], ]; $VAR1 = [ [ 'Q3.0', 'OK', '1900-01-01', 'N', 'O', 'O', 'X', 'Y' ], [ '12w', 'PL', '2000-01-02', 'N', 'P', 'O', 'X', 'A' ], ];

        The code would fail, because in the first array $princ, it contains 3 arrays or:
        $VAR1 = [ [ '12345', 'MONICA', '01/01/1900', '0X10' ], [ '000001', 'MARY L', '01/01/2000', '0111P' ], [ '8884', 'JOHN M.', '01/01/1932', '0OK8' ], ];

        So, if any of the others don't match the size of $princ I would get this error:
        Can't use an undefined value as an ARRAY reference at...

        That is becuase of $person only having 2 arrays:
        $VAR1 = [ [ 'Q3.0', 'OK', '1900-01-01', 'N', 'O', 'O', 'X', 'Y' ], [ '12w', 'PL', '2000-01-02', 'N', 'P', 'O', 'X', 'A' ], ];

        I was thinking if there is a way to check the first array for its number of elements and make sure that all the others would match its size, that way the code would have the right data structure. What do you think?