read PayflowPro reports using the report metadata using perl

I have a perl job using the cpan Business::PayflowPro::Reporting module which provides a simple way to retrieve reports from PayflowPro, but the reports are in a generic XML format like

{
  'columnData' => [
    {
      'colNum' => '1',
      'data' => 'value1'
    },
    {
      'colNum' => '2',
      'data' => 'value2'
    },
    ...
  ]
}

and I would like to access the metadata to reference the values using the dataName names which are defined like:

    {
      'dataName' => 'Transaction ID',
      'colNum' => '1',
      'dataType' => 'string'
    },
    {
      'dataName' => 'Time',
      'colNum' => '2',
      'dataType' => 'date'
    },
etc.

Is there any way to read the report xml using the column names defined in the metadata?
DalexanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
my $XML=
{
  'columnData' => [
    {
      'colNum' => '1',
      'data' => 'value1'
    },
    {
      'colNum' => '2',
      'data' => 'value2'
    },
  ]
};

my $dataName=
[
    {
      'dataName' => 'Transaction ID',
      'colNum' => '1',
      'dataType' => 'string'
    },
    {
      'dataName' => 'Time',
      'colNum' => '2',
      'dataType' => 'date'
    },
];

my %col;
@col{map$_->{colNum},@$dataName}=0..$#$dataName;
$dataName->[$col{$_->{colNum}}]{data}=$_->{data} for @{$XML->{columnData}};
use Data::Dumper;
print Dumper $dataName;
DalexanAuthor Commented:
This looks simple enough, but I'm a novice when it comes to perl...I tried this but get nothing but $VAR1 = []; from the print Dumper at the bottom of this code:

my $metadata = $bpr->getMetaDataRequest($reportId) or die $bpr->errstr;
my $page = $metadata->{numberOfPages};
my $columnMetaData = $metadata->{columnMetaData}; # col name
print Dumper($columnMetaData);

foreach my $p (1 .. $page) {
  my @reportDataRow = $bpr->getDataRequest($reportId, $p); # col value
  print Dumper(\@reportDataRow);
}
my %col;
@col{map$_->{colNum},@$reportDataRow}=0..$#$reportDataRow;
$reportDataRow->[$col{$_->{colNum}}]{data}=$_->{data} for @{$metadata->{columnData}};
print Dumper $reportDataRow;
ozoCommented:
What do you get from print Dumper $reportDataRow; and print Dumper $metadata->{columnData} before running it?
It looks like you are using @reportDataRow instead of $reportDataRow
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

DalexanAuthor Commented:
The attached file shows the results from the 3 print Dumper lines in the code:
tst1.lst
ozoCommented:
I don't see a  
     'data' => 'value1'
in
$VAR1 = {
          'columnMetaData' => [
            {
                                'dataName' => 'Transaction ID',
                                'colNum' => '1',
                                'dataType' => 'string'
            },
So what do you want to fill $dataName with?
DalexanAuthor Commented:
The first dump which is the one you are looking at is what I get when I call PayFlowPro requesting the metadata.  This only shows the format of the report...column names and data type.  The next call to get the actual data results in the second dump in the attached file above...it shows the data.  
What I don't understand is how to get the 2 files together so I can ask for the values of each row by column name.  Or is there no such coordination available between meta data and the xml data results?  Is this something I need to do in code?
ozoCommented:
#Is this what you want to do?
use strict;
use warnings;

my $XML = {
          'columnMetaData' => [
            {
                                'dataName' => 'Transaction ID',
                                'colNum' => '1',
                                'dataType' => 'string'
            },
            {
                                'dataName' => 'Time',
                                'colNum' => '2',
                                'dataType' => 'date'
            },
            {
                                'dataName' => 'Type',
                                'colNum' => '3',
                                'dataType' => 'string'
            },
            {
                                'dataName' => 'Account Type',
                                'colNum' => '4',
                                'dataType' => 'string'
            },
            {
                                'dataName' => 'Account Number',
                                'colNum' => '5',
                                'dataType' => 'string'
            },
            {
                                'dataName' => 'Account ABA',
                                'colNum' => '6',
                                'dataType' => 'string'
            },
            {
                                'dataName' => 'Amount',
                                'colNum' => '7',
                                'dataType' => 'currency'
            },
            {
                                'dataName' => 'Status',
                                'colNum' => '8',
                                'dataType' => 'string'
            },
            {
                                'dataName' => 'Description',
                                'colNum' => '9',
                                'dataType' => 'string'
            },
            {
                                'dataName' => 'Result Code',
                                'colNum' => '10',
                                'dataType' => 'number'
            },
            {
                                'dataName' => 'Result Code Msg',
                                'colNum' => '11',
                                'dataType' => 'string'
            },
            {
                                'dataName' => 'Customer Ref',
                                'colNum' => '12',
                                'dataType' => 'string'
            },
            {
                                'dataName' => 'Currency Symbol',
                                'colNum' => '13',
                                'dataType' => 'string'
            }
                            ],
          'numberOfPages' => '1',
          'reportId' => 'RE0649145468',
          'numberOfColumns' => '13',
          'pageSize' => '100',
          'numberOfRows' => '1'
};
my $dataName = [
    {
            'columnData' => [
            {
                              'colNum' => '1',
                              'data' => 'VPFDBC4EA216'
            },
            {
                              'colNum' => '2',
                              'data' => '2015-03-17 14:25:18'
            },
            {
                              'colNum' => '3',
                              'data' => 'Sale'
            },
            {
                              'colNum' => '4',
                              'data' => 'ACH-Checking'
            },
            {
                              'colNum' => '5',
                              'data' => '8460'
            },
            {
                              'colNum' => '6',
                              'data' => '272482061'
            },
            {
                              'colNum' => '7',
                              'data' => '1995'
            },
            {
                              'colNum' => '8',
                              'data' => 'P15'
            },
            {
                              'colNum' => '9',
                              'data' => 'Rejected'
            },
            {
                              'colNum' => '10',
                              'data' => '1'
            },
            {
                              'colNum' => '11',
                              'data' => '1: User Authentication Failed'
            },
            {
                              'colNum' => '12',
                              'data' => '2967732'
            },
            {
                              'colNum' => '13',
                              'data' => 'USD'
            }
                          ],
            'rowNum' => '1'
    }
    ];


my @data;
for( @$dataName ){
    my $rowNum=$_->{rowNum};
    for( @{$_->{columnData}} ){
      $data[$rowNum][$_->{colNum}]=$_->{data};
    }
}
my %data;
for( @{$XML->{columnMetaData}} ){
      $data{$_->{dataName}}=$data[1][$_->{colNum}];
}

use Data::Dumper;
print Dumper \%data;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DalexanAuthor Commented:
Been on vacation for a while, will try this on Monday and respond.
Suhas .Senior QA ManagerCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: ozo (http:#a40709521)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

suhasbharadwaj
Experts-Exchange Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.