On Friday 11 July 2003 9:50 pm, Michael Weber wrote:
> I have asked many questions of this group and gotten many good answers.
> No matter how dumb the question, I have always gotten a kind response.
>
> Thank you.
>
> The fruit of my recent efforts is a program that colorizes text for
> easier viewing.  I needed something that would highlight errors in log
> files as they scrolled by.  I couldn't find what I wanted so I wrote
> one.
>
> Here it is for all to use.  I hope someone besides myself can find it
> useful. send it along to whomever you like.
>
> I'm sure there are many improvements that the guru's who subscribe to
> this list can make, but it's my first effort and it works.  Hallelujah!
>
> Anyway, thanks for your help.
>
> -Michael

Hi Michael,

I liked you program so I took a copy.  Then I thought I'd use it as an 
excercise in 'PERL'ifying it. By this I mean appling some of the things I've 
read about writing perl scripts, such as removing transient variables where 
possible, elliminaing variables who's sole purpose is to control  the 
program, and above all take less typing.

The only variable I can't seem to get rid of is the $input_line, although I'm 
sure someone will tell me how.

Gary

#!/usr/bin/perl -w

# Copyright 2003 by Michael Weber
# Released into the public domain July 2003

# 'PERLified' by Gary Stainburn July 2003

use strict;

die "$0 requires a color file.  See readme.txt for more info.\n" if $#ARGV < 
0;

my %colours=('red'=>"\033[0;31m",
             'brown'=>"\033[0;33m",
             'blue'=>"\033[0;34m",
             'green'=>"\033[0;32m",
             'cyan'=>"\033[0;36m",
             'purple'=>"\033[0;35m",
             'gray'=>"\033[0;37m",

             'ltred'=>"\033[1;31m",
             'yellow'=>"\033[1;33m",
             'ltblue'=>"\033[1;34m",
             'ltgreen'=>"\033[1;32m",
             'ltcyan'=>"\033[1;36m",
             'ltpurple'=>"\033[1;35m",
             'white'=>"\033[1;37m",
             'ltgray'=>"\033[0;37m");

my $normal="\033[0m";

my %triggers;

open (CONF, $ARGV[0]) || die "Can't open config file $ARGV[0], $!\n";

while (<CONF>) {
  chomp;
  my ($trigger,$color)=split(",");
  $triggers{$trigger}=($colours{$color}) ? $colours{$color} : 
$colours{"white"};
}
  
close (CONF);

while (my $input_line = <STDIN>) {

  foreach (keys %triggers) {
    $input_line =~ s/($_)/$triggers{$_}$1${normal}/g;
  }    
  print $input_line;

}


-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000     


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to