Solved

Perl and XML::Simple

Posted on 2011-09-22
3
260 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

20 Experts available now in Live!

Get 1:1 Help Now