Nick Brown wrote: > 2009/7/16 John W. Krahn <[email protected]>: >> Nick Brown wrote: >>> On Jul 15, 11:15 am, [email protected] (John W. Krahn) wrote: >>>> Nick Brown wrote: >>>>> I'm trying to use Finance::OFX::Response to use a ofx statement I've >>>>> it downloaded from by bank website. >>>>> http://search.cpan.org/~bfoz/p5-Finance-OFX-20080303/lib/Finance/OFX/... >>>>> However there I'm getting the following perl compilation error: >>>>> Type of arg 1 to each must be hash (not subroutine entry) at >>>>> download_statements.pl line 67, near "->ofx ) " >>>>> for the below code: >>>>> $response = $mech->get($download_url . $count); >>>>> if (!$response->is_success) { >>>>> die 'Failed to load statements URL'; >>>>> } >>>>> $response = $mech->submit_form(form_name => $download_form_name, >>>>> button => \ >>>>> 'btnDownload'); >>>>> if (!$response->is_success) { >>>>> die 'Failed to get Statement Download'; >>>>> } >>>>> #print $mech->content(); >>>>> my $ofx_response = >>>>> Finance::OFX::Response->from_http_response($response); >>>>> while( my ($k, $v) = each $ofx_response->ofx ) { >>>>> print "key: $k, value: $v.\n"; >>>>> } >>>>> Can you suggest what is wrong the while loop I'm trying to use to >>>>> print the hash tree of the OFX? >>>> values(), keys() and each() require that their first argument must be a >>>> hash so if $ofx_response->ofx returns a reference to a hash then you >>>> have to dereference it: >>>> >>>> while( my ($k, $v) = each %{ $ofx_response->ofx } ) { >>>> print "key: $k, value: $v.\n"; >>>> } >>> Thanks, I've added the deference to the hash and it now compiles and >>> executes. >>> However I'm now getting a different run time error: >>> >>> Odd number of elements in hash assignment at >>> /usr/lib/perl5/vendor_perl/5.10.0/Finance/OFX/Parse.pm line 105, <> >>> line 1. >>> Use of uninitialized value $header{"OFXHEADER"} in numeric eq (==) at >>> /usr/lib/perl5/vendor_perl/5.10.0/Finance/OFX/Parse.pm line 107, <> >>> line 1. >>> Can't use an undefined value as a HASH reference at >>> download_statements.pl line 67, <> line 1. >>> >>> Do you have any suggestions to the cause of the this error? What >>> causing the undefine value as a HASH reference? >> Your best bet is to find out exactly what $ofx_response->ofx is returning. >> Try something like: >> >> use Data::Dumper; >> >> print Dumper $ofx_response->ofx; > > looks like its returning nothing! > > Odd number of elements in hash assignment at > /usr/lib/perl5/vendor_perl/5.10.0/Finance/OFX/Parse.pm line 105, <> > line 1. > Use of uninitialized value $header{"OFXHEADER"} in numeric eq (==) at > /usr/lib/perl5/vendor_perl/5.10.0/Finance/OFX/Parse.pm line 107, <> > line 1. > $VAR1 = undef;
Take a step back, and:
my @data = \($response, $ofx_response);
print Dumper \...@data;
If you still get nothing, you'll have to move up further in the program
until you find out exactly where things are not being assigned to properly.
To get a better idea of what is happening live-time, put a line like the
following just before the variable assignments that appears to be broken:
$DB::single=2;
Then call your program like this:
% perl -d program
You'll be dropped into the debugger. Use 'w' to "watch" certain
variables for changes. Use 'c' to jump to the breakpoint we added into
the program code (via $DB::simple=2), and use 's' to "single step" each
line. Here is an example:
The problem:
Odd number of elements in hash assignment at tests/ref.pl line 8.
The program:
#!/usr/bin/perl
use warnings;
use strict;
print "...Start\n";
$DB::single = 2; # the debugger run the program up until this point
# if I hit 'c' once
my %hash = ( this => 'that', these => 'those', me => );
my @array = qw ( one two three );
my @data = \( %hash, @array);
__END__
% perl -d tests/ref.pl
# the line you see on the screen is the one to be executed NEXT
DB<1> w %hash
DB<2> c
main::(tests/ref.pl:10): my %hash = ( this => 'that', these =>
'those', me => );
DB<2> s # single step the %hash assignment
Odd number of elements in hash assignment at tests/ref.pl line 10.
at tests/ref.pl line 10
Watchpoint 0: %hash changed:
old value: ''
new value: 'these', 'those', 'me', '', 'this', 'that'
### ^^^
There is the empty assignment that is completely throwing off the hash.
In your case, you may have to move the breakpoint(s) around a bit, and
"watch" different variables until you sort out where the faulty
assignment is being attempted.
Hope this helps, even a little bit...
Steve
DB<1> w %hash
DB<2> w @array
smime.p7s
Description: S/MIME Cryptographic Signature
