So I have a programming assignment where I need to parse multiple XML files and return their attributes in a readable format. Currently the script parses all of the files and stores all the details for each file at each position of an array. An example of the desired output would be:
J MIG-49 at location "85,20,0.1" is moving to "0.5,-0.5,-300
Below is the XML code for an example.
And here is my current Perl script.Code:<?xml version='1.0'?> <threat> <location>"85,20,0.1"</location> <ftype>J</ftype> <fmodel>MIG-49</fmodel> <movement_speed>"0.5,-0.5,-300"</movement_speed> </threat>
Code:my $count=0; opendir (DIR, "../folder") or die "$!"; my @feeds = grep {/threats.*?\.xml/} readdir DIR; close DIR; # The above 3 lines read in the XML files and store them in array feeds. for $threats(@feeds) { open (READ, $threats)||die"$!"; flock(READ, 1) || die "Can't lock xml: $!"; while (<READ>) { $all[$count].=$_ } close READ; $count++; } print @all; # report




Reply With Quote
