RE: Handling blank lines in while(<CONF>) construct
From: Michael Weber (mweber_at_alliednational.com)
Date: 03/05/04
- Next message: Tim Johnson: "RE: Disable Screensaver with Keyboard input"
- Previous message: Stefan Lubitz: "WG: Disable Screensaver with Keyboard input"
- Maybe in reply to: Michael Weber: "Handling blank lines in while(<CONF>) construct"
- Next in thread: R. Joseph Newton: "Re: Handling blank lines in while(<CONF>) construct"
- Reply: R. Joseph Newton: "Re: Handling blank lines in while(<CONF>) construct"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 05 Mar 2004 09:11:28 -0600 To: <david.leblanc@identity-solutions.com.au>,<sx@insecurity.org>, <beginners@perl.org>
Hi, David, et. al.
I probably should have given a little more info on what I want this
program to do. See below...
>>>> "David le Blanc" <david.leblanc@identity-solutions.com.au>
03/05/04 03:26AM >>>
>> -----Original Message-----
>> From: WC -Sx- Jones [mailto:sx@insecurity.org]
>> Sent: Friday, 5 March 2004 4:16 AM
>> To: Michael Weber
>> Cc: beginners@perl.org
>> Subject: Re: Handling blank lines in while(<CONF>) construct
>>
>> As far as this:
>>
>> "$yellow")}
>> elsif ( $conf_line[1] =~ "blue" ) {push(@color_array,
>>
>> Why not just:
>>
>> sub push_Colors() {
>> my $color = shift;
>> push(@color_array,$color)
>> }
>>
>> Called like:
>>
>> push_Colors($conf_line[1]);
>
>
>I thought he was pushing '$yellow' when he found 'yellow'.
>
Actually, the variable, along with all the other colors, is assigned
above the snippet of code like this...
my $yellow="\033[1;33m";
This is the terminal code to produce a yellow text output.
>Your code would just push the word found (ie, literal 'yellow')
>
>I think...<
>
What it creates is "${yellow}string${normal}" from "string". See
below...
>>One of us is confused ;-)
>>
>
>>
>> Unless of course your data input just has a color embedded:
>> sometextcolorredorbluebutwhoknows...
Pretty much accurate. The text stream looks like this:
[Snip from /var/log/maillog]
Feb 29 16:52:01 web-2 postfix/smtpd[32047]: 6AD1EBBEF: reject: RCPT
from unknown [12.127.237.226]: 554 <alliednational.com>: Helo command
rejected: Don't spoof my hostname; from=<lillingworth@america.com>
to=<jn@alliednational.com> proto=SMTP helo=<alliednational.com>
If I were watching my maillog file stream past, I would want to see
quickly if any messages are getting rejected. So I flag the word
"reject" in the line above to be red. So I can easily see why the
message was rejected, I would shade the string "Don't spoof my hostname"
to be ltblue.
To do this, I create a lookup table (@color_array) with all the color
names that maps the correct terminal codes ($color) to turn on and turn
off the colorization. I have a second array (@trigger_array) that holds
the texts to look for. The indices between the two map which colors to
prepend the the matching text. Then I do a substring replace in the
stream, in realtime,looking for "reject" (as found in @trigger_array)
and replace it with "<Make Me Red>reject<Make Me Normal>" and send that
line to the terminal. This array is created dynamically by the code
snip I started this thread with from a config file when the program
starts. Once the arrays are created, I never use this code again so
speed isn't criical.
Perl is fast enough that I can only see a split second delay using the
filter. Syslog takes longer than that to get the text into the file.
I posted the code to the list yesterday, but it hasn't shown up. I
guess the list doesn't like attachments. I will re-post it in-line
later. There are still a few tweaks that people have come up with that
I want to include.
Thanx, all for your help!
-Michael
- Next message: Tim Johnson: "RE: Disable Screensaver with Keyboard input"
- Previous message: Stefan Lubitz: "WG: Disable Screensaver with Keyboard input"
- Maybe in reply to: Michael Weber: "Handling blank lines in while(<CONF>) construct"
- Next in thread: R. Joseph Newton: "Re: Handling blank lines in while(<CONF>) construct"
- Reply: R. Joseph Newton: "Re: Handling blank lines in while(<CONF>) construct"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|