RE: Handling blank lines in while(<CONF>) construct

From: Michael Weber (mweber_at_alliednational.com)
Date: 03/05/04


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



Relevant Pages

  • Re: increasing the size of a byte array and reading streams
    ... > reading the stream below (where buf is a byte array). ... When you're reading a file, for example, and you know that the file is ... There are times, however, when it makes sense to read a stream in small ... write those uncompressed bytes to your secondary MemoryStream. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to save C++ objects using Cocoa?
    ... from my perspective it seems like with a byte stream I have to invent ... have to archive the array. ... imply that Cocoa streamlines the whole lot; ... flattening the data to saving it; I wasn't sure why, or if, this was ...
    (comp.sys.mac.programmer.help)
  • Re: How to save C++ objects using Cocoa?
    ... from my perspective it seems like with a byte stream I have to invent ... have to archive the array. ... imply that Cocoa streamlines the whole lot; ... flattening the data to saving it; I wasn't sure why, or if, this was ...
    (comp.sys.mac.programmer.help)
  • Re: How to save C++ objects using Cocoa?
    ... NSKeyedArchiver's archiveRootObject:toFile: method, using the array ... from my perspective it seems like with a byte stream I have to invent ... I was confused between the flattening, and the writing process, but I ... imply that Cocoa streamlines the whole lot; ...
    (comp.sys.mac.programmer.help)
  • Re: what is the best datatype for..
    ... I would definitely favor the array of ints, ... I mean are all the values 0-255 or 0-65535 etc. So a huge network stream ...
    (microsoft.public.dotnet.languages.csharp)