So i moved to the Ubuntu operating system recently to see how it was like and i came across the syslog which proves to be quite interesting. So i decided to create a script that will run through the syslog and search for key terms with a regex and output this to another text file. this is what i got so far

#!/usr/bin/perl use strict; use warnings; my @array=(); open(my $keyword,'<', "keyword.txt") or die "Couldn't open file file.t +xt, $!"; open(my $sys,'<', "syslog") or die "Couldn't open file file.txt, $!"; #open($keyword,'>' "keyword.txt") || die "Couldn't open file file.txt, + $!"; #open my $keyword, '>' , $file_location3 or die "can't open Keywords:" + $!; # gives keywords.txt the file handle keyword and shows + #error message if it fails to open #open my $sys, '>' , $file_location2 or die $!; # same as above open(my $fh, '>', 'output.txt'); #my $file_location2 = "syslog"; #my $file_location3 = "keyword.txt"; #arraylisy goes here my $Keyword_or = join '|' , map {chomp;qr/\Q$_\E/} <$keyword>; # lists + all lines in indicated file and joins the list in 1 string #regex +here removes new line from each line and uses literal regex #which +matches even those words with dots my $regex = qr|\b($Keyword_or)\b|; # this regex will match #all the keywords stored in keyword +s txt file #@array = $Keyword_or; foreach $regex(@array) { #while (/regex/g) #{ #print $NEW "$.: $1"; print $fh $regex; #} #return $keyword; #return $sys; #return $NEW; #print $fh $NEW; close $fh; }

While this code does compile with no errors it doesn't actually output anything and i also realized that my array is also empty. As im still new to perl Can anyone tell me how i would push the results of the regex to an arraylist and output it ?


In reply to Output problems by shingster08

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.