First things first - I get a not well-formed error when I try to run your code. The fix is to quote the value of PROGRAM_COUNT in the Participant tag (PROGRAM_COUNT="3"). (Actually, that's the second error I got. The first thing I did was add use strict; use warnings; and then declare all of the variables.)
On to business. From what I can tell, you're getting confused about how to use references.
For example, in the following line you are assigning an array reference to an array, which is probably not what you intended to do.
my @program_array = $XMLref->{Response}->[0]->{Program};
Either expand (dereference) the array ref to an array when you assign it, or simply assign the reference.
my @program_array = @{ $XMLref->{Response}[0]{Program} };
my $program_aref = $XMLref->{Response}[0]{Program};
Secondly, you've got a typo in $programs->{status};. This key is capitalized in the XML ('Status').
Update: Thirdly, see Thelonius' reply to this node.
Here is a corrected version of the code:
if( ref( $XMLref->{Response}[0]{Program}[0] ) ) {
my $program_arrayref = $XMLref->{Response}[0]{Program};
# Walk through the programs
foreach my $programs_href ( @{ $program_arrayref } ) {
my $status_aref = $programs_href->{Status};
my $one_program_name = $programs_href->{NAME};
# Walk through the statuses within each program
foreach my $status_href ( @{ $status_aref } ) {
my $hold_desc = $status_href->{StatusDesc}[0];
my $hold_start = $status_href->{StatusDate}[0];
my $hold_end = $status_href->{StatusEndDate}[0];
# a lot of other processing here
print join( ':', $one_program_name, $hold_desc,
$hold_start, $hold_end ), "\n";
}
}
}
This prints:
Balance:nl1 has been published:04/20/05:
Balance:mas has been published:04/20/05:04/26/06
Breathe:nl1 has been published:04/20/05:
Breathe:mas has been published:04/20/05:04/26/06
The following links may help:
HTH
Update:Thanks to Thelonius for pointing out a correction to the code that I made but neglected to mention. I guess I was fixing faster than I was documenting. :-)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.