Your immediate error:
At this point in the code, the $rulefile has not been declared (which is done with the my built-in), leading to a compile-time error, and has not been defined or initialized (which is done by assigning a value to it), leading to a run-time error once the compile-time error has been fixed.print "RULE_FILE : $rulefile \n";
Next error (assuming you have added the my function for every new variable):
This does not define a directory, so that the next code line will not work as expected. If you want to define a directory, you may want to have:my $rulesdir = "C:\\Snort\\rules\\*.rules";
or perhaps simply:my $rulesdir = "C:\\Snort\\rules\\";
Next issue:my $rulesdir = "C:/Snort/rules/";
From looking at your directory paths, you're working on Windows. The ls command is a Unix system command, it will not work under Windows. You should use Perl internal commands rather than system calls whenever possible. Try this:@rulefiles = `ls $rulesdir\/*.rules`;
Another issue (assuming that you have used my and indented your code correctly, as recommended, and straitening a bit the syntax):my $rulesdir = "C:\\Snort\\rules"; my @rulefiles = glob "$ruledir/*.rules";
Here, I have corrected and/or improved the syntax, but you have a serious algorithmic problem: you are looping over a list of files (@rulefiles) and, each time through the loop, are assigning the contents of the file to @rules, meaning that when you read the content of the second file, you clobber the previous content of @rules (i.e. what you read from the first file), and so on, so that, in fine, you end up with only the content of the last file.for my $rulefile (@rulefiles){ open my $INFILE, "<", $rulefile or die "Can't open $rulefile $!"; my @rules = <$INFILE>; close $INFILE; }
There are several (actually, many) other issues, but at least, I hope this will help you going forward.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Scanning multiple files from Snort rules one by one and extracting a particular part to another file - File Handling
by Anonymous Monk on Jul 22, 2015 at 09:31 UTC | |
by Laurent_R (Canon) on Jul 22, 2015 at 09:35 UTC | |
|
Re^2: Scanning multiple files from Snort rules one by one and extracting a particular part to another file - File Handling
by edison.pioneer (Initiate) on Jul 22, 2015 at 18:10 UTC |