shingster08 has asked for the wisdom of the Perl Monks concerning the following question:
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 ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Output problems
by 1nickt (Canon) on Dec 07, 2016 at 15:06 UTC | |
|
Re: Output problems
by SuicideJunkie (Vicar) on Dec 07, 2016 at 15:14 UTC | |
|
Re: Output problems
by kcott (Archbishop) on Dec 08, 2016 at 03:38 UTC | |
|
Re: Output problems
by stevieb (Canon) on Dec 07, 2016 at 14:56 UTC | |
by shingster08 (Initiate) on Dec 07, 2016 at 14:58 UTC |