So I'm working on a program 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 for each line 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 reference.
And here is my current Perl script.
As stated previously, I need to parse out the fields for each file as I'll need them later. I'm not quite sure how to do this though as I'm relatively new to Perl. Any help would be great.
J MIG-49 at location "85,20,0.1" is moving to "0.5,-0.5,-300"
Below is the XML code for reference.
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
Comment