Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Annoying PERL Problem

Options
  • 02-07-2007 10:38am
    #1
    Closed Accounts Posts: 909 ✭✭✭


    Hi,

    Im generating a PDF report using PERL but am having problems with a simplish problem Im thinking.

    When I manually code $records a sfollows it generates the PDF report no problem:
    $records = [
    
    [$ww[0], $ww[3], $ww[1], $ww[4],$ww[2],"Score: fd[0]. Last goal on $fd[3]. Scorer is $fd[0]."],
    
    ];
    
    $data->{data_array} = @records;
    $report->render_data($data);
    $report->save;
    


    However, I would like to generate each line of the matrix dynamically. For example if there are 3 goals this is what I should write in records:
    $records = [
    
    [$ww[0], $ww[3], $ww[1], $ww[4],$ww[2],"Score: fd[0]. Last goal on $fd[3]. Scorer is $fd[0]."],
    
    
    [$ww2[0], $ww2[3], $ww2[1], $ww2[4],$ww2[2],"Score: fd2[0]. Last goal on $fd2[3]. Scorer is $fd2[0]."],
    
    
    [$ww2[0], $ww2[3], $ww2[1], $ww2[4],$ww2[2],"Score: fd2[0]. Last goal on $fd2[3]. Scorer is $fd2[0]."]
    
    ];
    

    Does anyone know how I can dynamically create the Matrix? Ive tried using a for loop but it didnt work out for me. Help!!!

    G


Comments

  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    This is a job for my favourite section of the perl docs - perldsc, the Data Structures Cookbook. Look at the Generation of an ARRAY of Arrays section.

    The Data::Dumper module can be helpful to confirm that your data structure looks how it should.


  • Registered Users Posts: 1,287 ✭✭✭joe_chicken


    /edit I'm stupid... should have read the problem


  • Closed Accounts Posts: 909 ✭✭✭Gareth37


    daymobrew wrote:
    This is a job for my favourite section of the perl docs - perldsc, the Data Structures Cookbook. Look at the Generation of an ARRAY of Arrays section.

    The Data::Dumper module can be helpful to confirm that your data structure looks how it should.

    Thanks. Wow. Every day i realise I have a lot more to learn about Perl. Will see how i get on. Thanks.


  • Closed Accounts Posts: 909 ✭✭✭Gareth37


    Well I didnt need the fancy modules but i got it working. It was trivial in the end. Thanks for the link. Here is 1 solution:
    $records->[19][0] = "One";
    $records->[19][1] = "Two";
    $records->[19][2] = "etc";
    

    I can access the array dynamically using a for loop now using the above simple array access methods. :) I need to learn more thats all.

    G


Advertisement