Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: XML::Simple question

by jbt (Chaplain)
on Aug 01, 2009 at 16:47 UTC ( [id://785115]=note: print w/replies, xml ) Need Help??


in reply to XML::Simple question

Assuming $xmlconfig looks something like:

my $xmlconfig = { 'order' => { 'item-info' => { 'batch' => { 'batch-member' => { 'aid' => {} } } } } };
'batch-member' is hash reference, and not an array reference. Check the three lines after the while loop dereferencing $i:

while(my $batch_aid = $xmlconfig->{order}->{'item-info'}->{batch}->{'b +atch-member'}->{aid}){ my $batch_pii = $xmlconfig->{order}->{'item-info'}->{batch}->{'batch +-member'}->{$i}->{'pii'}; my $batch_pit = $xmlconfig->{order}->{'item-info'}->{batch}->{'batch +-member'}->{$i}->{'pit'}; my $batch_doi = $xmlconfig->{order}->{'item-info'}->{batch}->{'batch +-member'}->{$i}->{'doi'}; $orderin{$batch_aid} = { 'pit' => $batch_pit, 'pii' => $batch_pii, 'doi' => $batch_doi, }; my $Eextra=''; $i++; $orderin{subitem}='Yes'; }

Replies are listed 'Best First'.
Re^2: XML::Simple question
by raj_monk (Novice) on Aug 02, 2009 at 11:37 UTC
    Thanks Monks, I have solved by using Forcearray
    $xmlconfig = XMLin($xml,ForceArray => [qw{batch-member}]); my $count= (@{$xmlconfig->{order}->{'item-info'}->{batch}->{'batch-mem +ber'}}); #print $count; for ($i=0; $i<=$count; $i++ ){ my $batch_aid = $xmlconfig->{order}->{'item-info'}->{batch}->{'batch +-member'}->[$i]->{'aid'}; my $batch_pii = $xmlconfig->{order}->{'item-info'}->{batch}->{'batch +-member'}->[$i]->{'pii'}; my $batch_newpii=$batch_pii; $batch_newpii=~s/[^A-z0-9]//gi; my $batch_pit = $xmlconfig->{order}->{'item-info'}->{batch}->{'batch +-member'}->[$i]->{'pit'}; my $batch_doi = $xmlconfig->{order}->{'item-info'}->{batch}->{'batch +-member'}->[$i]->{'doi'}; $orderin{$batch_aid} = { 'pit' => $batch_pit, 'pii' => $batch_pii, 'doi' => $batch_doi, }; my $Eextra=''; $i++; $orderin{subitem}='Yes'; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://785115]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found