At 02:18 PM 4/19/01 -0400, Jen wrote:
>I'm brand new to perl and trying to solve a problem.. Here is what I'm
>trying to do:
>
>General: Within a directory I want to open every file ending in .nasl,
opendir DIR, $directory or die "opendir: $!\n";
foreach my $file (grep /^\.nasl$/, readdir DIR) {
open IN, $file or die "Open $file: $!\n";
>look for three strings and capture text after each string till I see a "
>or ),
while (<IN>) {
next unless /(string1|string2|string3)([^")]*)/;
>then take that text and append it to a single file delineated by a comma,
>tab, or | symbol.
print OUT $2, $delim{$1};
}
}
You need to first create a hash %delim whose keys are string1, string2, and
string3, and whose corresponding values are comma, tab, |.
That ought to get you started.
>More detailed:
>Perform the following operations on every file ending in .nasl within /tmp
>(attached is sample of file to be opened) with an extension of *.nasl
>
>1. Search file for the following strings:
>
>script_id(NNNNN);
>script_cve_id("AAA-NNNN-NNNN");
>name["english"] = "XXXXXXXXXXXXXXXXXXX";
>
>2. Pull the text associated with the capitalized text above from each file
>(listed below). I've put comments as to the data type.
>
>NNNNN # integer (5) characters in length
>AAA-NNNN-NNNN # alphanumeric text string Example: Always CVE-year-ID or
>CAN-year-ID
>XXXXXXXXX # text -- This is just the name of the script
>
>3. output this to one file somehow delineated by a comma, tab or |:
>
>NNNNN,AAA-NNNN-NNNN, XXXXXXXXX
>
>NNNNN AAA-NNNN-NNNN XXXXXXXXX
>
>NNNNN|AAA-NNNN-NNNN|XXXXXXXXX
>
>4. I have attached a sample nasl file I'm parsing
>below...................................................................................
>thanks for your help!
>
>If this is too lofty of a question to ask for help with, I understand.
>
>
>
>
>
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com