I'm not sure just how big each rule file is, but reading in all of the file seems wasteful when you only want the first part. To carry on with Laurent R's example, you could extract the header part in the first loop and save it into an array for processing later:
my @headers; for my $rulefile (@rulefiles){ open my $INFILE, "<", $rulefile or die "Can't open $rulefile $!"; my $header; while ( my $line = <$INFILE> ) { # see if this line contains opening bracket if ( $line =~ m/\(/ ) { my $pos = index( $line, '(' ); last unless $pos > 0; $header .= substr( $line, 0, $pos ); last; } else { $header .= $line; } } close $INFILE; push( @headers, $header ) if $header; } for my $header ( @headers ) { print "\nHeader:\n$header\n"; # now process the header }

In reply to Re: Scanning multiple files from Snort rules one by one and extracting a particular part to another file - File Handling by tangent
in thread 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.