I'm a novice to PERL and I need to finish writing this for my project in a week. I've written to the following code for Snort rule base.What the program is supposed to do is this. Go to Snort folder in C: drive.In that folder, there will be another folder called "rules", in which there will be files by the extension ".rules". I've to extract only the header part of the file. A rule file can be divided into two types: 1) Rule header and 2) Rule options. I'm interested only in rule header. It begins with the beginning of the file (And most of the times the first word is "Alert") till the first opening bracket is encountered. I want to extract only the header part,convert it to hex (using sprintf and ord)and save it to a file called "camdata.txt".Before including use warnings and use strict,I was getting errors related to scalar found where operator expected. Now I get $rulefile requires explicit package name

use strict; use warnings; # use dignostics; print "RULE_FILE : $rulefile \n"; $rulesdir="C:\\Snort\\rules\\*.rules"; @rulefiles = `ls $rulesdir\/*.rules`; $camfile = "camdata.txt"; # print "RULE_FILE : $rulefile \n"; for $rulefile(@rulefiles){ open(INFILE, "<".$rulefile) or die "Can't open ".$rulefile."\n"; @rules=<INFILE>; close(INFILE); # $headerParts = 0; # why bhave I taken a header part here? # $headerParts++; for($rule =~ /alert/) # $prule = $rule; $prule = substr($prule, 0, index($prule, '(')); print "extracted header : $prule \n"; } # Store header-part # if ($headerParts == 1){ # push(@prules, $prule); }

In reply to Scanning multiple files from Snort rules one by one and extracting a particular part to another file - File Handling by edison.pioneer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.