guri guri - 1 year ago 91
Perl Question

perl extract and parse

I am new to Perl and trying to figure out the issue with the script.

2.what changes I can make to accept multiple XML one by one through command line?

3.How to direct o/p of function to text file?

4.How to direct o/p of function to i/p to other function as an argument?

Answer Source

The first question is simple: you declare @vuln and later use %vuln. You can store hash in an array if you wish, but the symbol %vuln has not been declared. So declare my %vuln;.

As for all others, handle it in the driver. The function extract is mostly good as it stands, reading and parsing a single file. Then, there are a number of ways to go about that.

You can loop over @ARGV, calling extract for each submitted file. For example

foreach my $file (@ARGV) 
    die "No file $file " if not -e $file;

    my %vuln = NVD::extract($file);

    # deal with %vuln ...

However, given all other checking you'd have to do, it is better to handle command-line arguments using the core module Getopt::Long. It also has options for reading a list of inputs into an array.

Once you are in a loop like the one above (over an array assigned by Getopt::Long), you can open an output file each time through, and write what you need for each processed input file (%vuln). How exactly you'd do that depends on specifics of what should be written to the output file(s).

You can also call other functions after extract and pass %vuln to them.

In principle I'd suggest passing a complex hash around by reference.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download