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

I know, I just can't think on how to fix it.

Replies are listed 'Best First'.
Re^3: Can't use string as an ARRAY ref
by GotToBTru (Prior) on Aug 21, 2015 at 15:31 UTC

    It looks like you might be trying to construct a table, possibly in HTML. I would suggest looking into the CPAN modules for that purpose. They will dictate your data structure, at least to an extent.

    Otherwise, what do you want the output to look like?

    Dum Spiro Spero
      Its actually PDF.
      use PDF::API2; use PDF::Table;
      The issue is in the "for loop", cause if I just pass something like this out side of the "for loop" it goes wel:

      my $extra_data = $data->{$num}{extra}; unshift @$extra_data,["City", "Street", "ZIP"];
      I even tried passing this:
      add_more( data => $type->[$i], );
      as:
      add_more(data => @{ $type->[$i] }, );

      Course, it didn't work!

        Here is a working example for creating tables in PDF using your structures. I was not able to understand what the loop was for. Can you modify it to demonstrate the problem that you have ?.

        #!/usr/bin/perl use strict; use warnings; use PDF::API2; use PDF::Table; use Data::Dump 'pp'; my $data = { 1=>{ 'main' => [ [ '12345', 'MONICA', '01/01/1900','0X10' ], [ '000001', 'MARY L', '01/01/2000','0111P' ], [ '8884', 'JOHN M.','01/01/1932','0OK8' ],], 'type' => [ ['Main','1900','Red'], ['APT', '1290','Blue'], ['AVAL','1921','Green'],], 'princ' => [ ['Q3.0', 'OK','1900-01-01','N','O','O','X','Y'], ['12w','PL','2000-01-02','N','P','O','X','A'],], }}; my $pdftable = new PDF::Table; my $pdf = new PDF::API2( -file => "table.pdf" ); my $page = $pdf->page; $pdf->mediabox(842, 595); foreach my $num ( keys %{$data} ) { my $main = $data->{$num}{main}; unshift @$main,["Account", "Name", "Date", "Code #"]; #pp $main; my $type = $data->{$num}{type}; unshift @$type,["HOUSE", "YEAR", "COLOR"]; #pp $type; my $princ = $data->{$num}{princ}; unshift @$princ,["AC #","Name", "DATE", "Ref","Case #1","Case #2", " +Case #3", "Case #4"]; #pp $princ; #for my $i ( 0 .. $#{ $main } ){ # more stuff my $y = 500; (undef,undef,$y) = add_more( data => $main, y => $y ); (undef,undef,$y) = add_more( data => $type, y => $y-10 ); (undef,undef,$y) = add_more( data => $princ, y => $y-10 ); #} } $pdf->save; sub add_more{ my (%args) = @_; my $data = $args{data}; my $y = $args{y}; $pdftable->table( $pdf, $page, $data, -x => 100, -start_y => $y, -next_y => 700, -start_h => 300, -next_h => 500, -w => 570, -padding => 5, -column_props=>[ map{ { justify => 'center' } }1..@{$data->[0]} ], ); }
        poj