Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Perl and XML::Simple

Posted on 2011-09-22
3
Medium Priority
?
271 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 2000 total points
ID: 36582545
my @table = $perl->{Entries};
my @ntable = $table[0];
my $count = @ntable;
print "Count is $count\n";
0
 
LVL 1

Author Closing Comment

by:nachtmsk
ID: 36584238
Perfect. Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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…
Six Sigma Control Plans

783 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