Solved

Perl and XML::Simple

Posted on 2011-09-22
3
259 Views
Last Modified: 2012-05-12
Hi,
Please see code below. I am using XML::Simple to unravel an XML File. My end purpose to this is to extract all data out of the XML file and import the data into a database.
My question:  Is there a simple way to tell how many records I actually have in the XML file. I want to create a  'for' loop but I don't know how many iterations to give it.
I'm sure there is a simple solution here I am not seeing. Thanks!
use XML::Simple qw(:strict);
use Data::Dumper;

# $rsp contains the XML that I retrieve using a cURL call to an external source. 
$cnt=0;

my $xs = XML::Simple->new(ForceArray => 1, KeepRoot => 1, KeyAttr=>[]);
my $config = $xs->XMLin($rsp);

#print Dumper($config);


## SO what I want to do here is create a loop using and index to loop
# Through all possible entries in my XML data. The line below prints out
# correctly the first 'Entry' in 'Entries' of Field 16. 


$dataFromField16= "$config->{'Entries'}->[0]->{'Entry'}->[0]->{'Field16'}->[0]";

print "$dataFromField16\n";

Open in new window

0
Comment
Question by:nachtmsk
3 Comments
 
LVL 12

Expert Comment

by:mwochnick
ID: 36581853
why not use a while loop and process until you run out of records?
0
 
LVL 1

Accepted Solution

by:
rajeeshb earned 500 total points
ID: 36582545
my @table = $perl->{Entries};
my @ntable = $table[0];
my $count = @ntable;
print "Count is $count\n";
0
 

Author Closing Comment

by:nachtmsk
ID: 36584238
Perfect. Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now