Wednesday, September 01, 2004

An OO Text filter library in Perl

Have put together a skeleton of a Region matching library in Perl. Idea was triggered from the log analysis script that I was writing last week. That worked pretty well, except for the fact that my fiance wanted to do other little bits with some other regions of the same file.
And then I got thinking and realized that 90% of the time I am trying to match text delimited by some patterns and trying to do something with the text in between - for instance, add log statements at start and end of function calls in a VB.NET source, clean up objects at end of function etc etc.

public function f
----
----
----
.
.
----
end function

public function g
----
----
----
.
.
----
end function



Also, being able to string two (or more) filters one behind the
other was another must have feature. i.e., filtered output of the first becomes input for the second.

And being able to negate a filter would be of added use - I guess it'll just ease up stuff syntactically.

So I've been spending quite some time in the past two days and have finally the app code looks simple as I'd wanted...


#! /bin/perl

use strict;
use TextRegion::StartFilter;
use TextRegion::StartEndFilter;
use TextRegion::AndFilter;

my ($filter1, $filter2, $andfilter);
sub onMatchBegin; #app code callback
sub onMatchEnd; #app code callback
$| = 1;
$filter1 = new TextRegion::StartEndFilter('^\w+:\d+>\s*sysbuf', '^\**DONE\**ERRORBUF');
$filter2 = new TextRegion::StartFilter('^SWER');
$andfilter = new TextRegion::AndFilter($filter1, $filter2);
$filter2->onBeginEvent(\&onMatchBegin);
$filter2->onRegionEndEvent(\&onMatchEnd);

$andfilter->start;
while(<>) {
$andfilter->apply($_);
}
$andfilter->end;


Am I on top of the world today!!! :D :D. Actually, the fun part of
programming is that spark of an idea that you can build and give a tangible shape - always beats me how people can't not like programming.

An OO Text filter library in Perl

Have put together a skeleton of a Region matching library in Perl. Idea was triggered from the log analysis script that I was writing last week. That worked pretty well, except for the fact that my fiance wanted to do other little bits with some other regions of the same file.

And then I got thinking and realized that 90% of the time I am trying to match text delimited by some patterns and trying to do something with the text in between - for instance, add log statements at start and end of function calls in a VB.NET source, clean up objects at end of function etc etc.



public function f

----

----

----

.

.

----

end function


public function g

----

----

----

.

.

----

end function






Also, being able to string two (or more) filters one behind the

other was another must have feature. i.e., filtered output of the first becomes input for the second.


And being able to negate a filter would be of added use - I guess it'll just ease up stuff syntactically.


So I've been spending quite some time in the past two days and have finally the app code looks simple as I'd wanted...




#! /bin/perl


use strict;

use TextRegion::StartFilter;

use TextRegion::StartEndFilter;

use TextRegion::AndFilter;


my ($filter1, $filter2, $andfilter);

sub onMatchBegin; #app code callback

sub onMatchEnd; #app code callback

$| = 1;

$filter1 = new TextRegion::StartEndFilter('^\w+:\d+>\s*sysbuf', '^\**DONE\**ERRORBUF');

$filter2 = new TextRegion::StartFilter('^SWER');

$andfilter = new TextRegion::AndFilter($filter1, $filter2);

$filter2->onBeginEvent(\&onMatchBegin);

$filter2->onRegionEndEvent(\&onMatchEnd);


$andfilter->start;

while() {

$andfilter->apply($_);

}

$andfilter->end;





Am I on top of the world today!!! :D :D. Actually, the fun part of

programming is that spark of an idea that you can build and give a tangible shape - always beats me how people can't not like programming.

Saturday, August 28, 2004

Perl - you'll either love it or you'll hate it, but you won't ignore it if you want to get things done!

Have spent the better part of yesterday night writing a Perl script to
aid my fiance' in doing some log analysis. And I'm no Perl guru - my biggest Perl program till date wouldn't have been more than a 100 lines.
Here's my raves and rants on it
Raves

  1. Most powerful reg ex capabilities with a full programming language
    to back it up!

  2. Large and powerful standard library.

  3. Platform independent
    Have windoze at work, usually am on a cygwin console and have
    linux/windows dual boot at home. Perl doesn't complain!



Rants

  1. Syntax - I've never got used to the ultra concise Perl vars. But
    then, I dont use it regularly enough. Still, the syntax just isnt
    readable.

  2. Syntax isn't orthogonal - guess what I'm trying to say is that there
    isn't one and only one way to achieve something. While this is totally
    against the Perl mantra of "There's more than one way to do it", in
    spite of using it on and off, I've never been able to embrace

    1. References

    2. Subs

    3. OO Perl

    4. Writing perl mods



  3. I've used all of them at sometime or the other but the next time I
    pick up Perl to do some nifty little script, I find myself going
    through perlsub, perlref, perlreftut and perltoot - not nice!

I guess at sometime I did come across Python - which is supposed to
address all the shortcomings of Perl while retaining the pluses. But then once I got everything set up, saw that its indentation sensitive!! Now does that remind me of something....called FORTRAN ??

Anyway, it put me off so much that I never took a look at it again - probably I should, and be more generous while at it!

Meanwhile, I'll use Perl the next time I need to write a nifty little
script to do some text analysis.

Interested? - I'll recommend Robert's perl tutorial.
Programmer: n. Person who spends 10 hours automating something that
takes an hour manually just so that


  1. He can see his program complete the work in 1 hour.

  2. He can tell his poor kith and kin what a great guy he is.

Perl - you'll either love it or you'll hate it, but you won't ignore it if you want to get things done!

Have spent the better part of yesterday night writing a Perl script to aid my fiance' in doing some log analysis. And I'm no Perl guru - my biggest Perl program till date wouldn't have been more than a 100 lines.
Here's my raves and rants on it
Raves

  1. Most powerful reg ex capabilities with a full programming language to back it up!

  2. Large and powerful standard library.

  3. Platform independent. Have windoze at work, usually am on a cygwin console and have linux/windows dual boot at home. Perl doesn't complain!


Rants

  1. Syntax - I've never got used to the ultra concise Perl vars. But then, I dont use it regularly enough. Still, the syntax just isnt readable.

  2. Syntax isn't orthogonal - guess what I'm trying to say is that there isn't one and only one way to achieve something. While this is totally
    against the Perl mantra of "There's more than one way to do it", in spite of using it on and off, I've never been able to embrace

    1. References

    2. Subs

    3. OO Perl

    4. Writing perl mods


    I've used all of them at sometime or the other but the next time I pick up Perl to do some nifty little script, I find myself going through perlsub, perlref, perlreftut and perltoot - not nice!


I guess at sometime I did come across Python - which is supposed to address all the shortcomings of Perl while retaining the pluses. But then once I got everything set up, saw that its indentation sensitive!! Now does that remind me of something....called FORTRAN ??

Anyway, it put me off so much that I never took a look at it again - probably I should, and be more generous while at it!
Meanwhile, I'll use Perl the next time I need to write a nifty little script to do some text analysis.
Interested? - I'll recommend Robert's perl tutorial.

Programmer: n. Person who spends 10 hours automating something that takes an hour manually just so that

  1. He can see his program complete the work in 1 hour.

  2. He can tell his poor kith and kin what a great guy he is.

Friday, August 27, 2004

A new day, some tweaks and a little bit of *nix

So I managed to get myself a gmail account - raghu dot rajagopalan at gmail dot com :). And I love google groups access. However, wanted to know if there is some way where my posts don't show my email address.

Have posted a query to google feedback - will let you know if something comes of it.

Meanwhile have started looking at NUnitForms - have to try out some code to see if it's as nice as nunit. If any of you have tried it out, please do post your suggestions and feedback on the tool.

On an aside, with console driven tools (nant, nunit etc) gaining popularity, I find myself running the cmd.exe a lot more. I've been a long time (> 2 years) fan of cygwin for running bash and other *nix tools on windows and it certainly helps that I can run all .net command line tools from there. However, it does have its wrinkles - it recognizes only unix style paths and this sometimes gets me into trouble. So for that I have to resort to cmd.exe - where I've always missed tab completion for files and folders. Found a couple of tweaks that get you *nix behavior on windows:


  1. Command prompt in the context menu in Explorer (win 2000)

    1. Open explorer

    2. Tools->Folder Options ->File Types

    3. Type n in the list boxand navigate to 'Folder' item

    4. Click Advanced in the bottom frame. An Edit File Type window pops up.

    5. Click New - and in the Action Box, enter Command Prompt. In the Application Box, enter "cmd.exe".

    6. Close all windows and restart explorer. You should have a new context menu for folder items called "Command Prompt"




  2. Tab completion as in *nix.


    1. Open the registry with Regedit.

    2. Navigate to the key

      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor


    3. Set the values for CompletionChar and PathCompletionChar to 0x09


    [You can download power toys for various windows versions for this behavior, but I like to do it without yet another download]



A new day, some tweaks and a little bit of *nix

So I managed to get myself a gmail account - raghu dot rajagopalan at gmail dot com :). And I love google groups access. However, wanted to know if there is some way where my posts don't show my email address.


Have posted a query to google feedback - will let you know if something comes of it.


Meanwhile have started looking at NUnitForms - have to try out some code to see if it's as nice as nunit. If any of you have tried it out, please do post your suggestions and feedback on the tool.


On an aside, with console driven tools (nant, nunit etc) gaining popularity, I find myself running the cmd.exe a lot more. I've been a long time (> 2 years) fan of cygwin for running bash and other *nix tools on windows and it certainly helps that I can run all .net command line tools from there. However, it does have its wrinkles - it recognizes only unix style paths and this sometimes gets me into trouble. So for that I have to resort to cmd.exe - where I've always missed tab completion for files and folders. Found a couple of tweaks that get you *nix behavior on windows:




  1. Command prompt in the context menu in Explorer (win 2000)



    1. Open explorer


    2. Tools->Folder Options ->File Types


    3. Type n in the list boxand navigate to 'Folder' item


    4. Click Advanced in the bottom frame. An Edit File Type window pops up.


    5. Click New - and in the Action Box, enter Command Prompt. In the Application Box, enter "cmd.exe".


    6. Close all windows and restart explorer. You should have a new context menu for folder items called "Command Prompt"






  2. Tab completion as in *nix.




    1. Open the registry with Regedit.


    2. Navigate to the key

      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor



    3. Set the values for CompletionChar and PathCompletionChar to 0x09




    [You can download power toys for various windows versions for this behavior, but I like to do it without yet another download]





Thursday, August 26, 2004

I'm back...

Havent really been active on the blog - kind of ignored it till now. Anyway, I'm back, fwiw. There's been quite a lot of changes here and I guess that's the thing that's kept me from blogging - add to it the fact that I'm new to maintaining a journal on the web.

These days am looking for some generous person to invite me to Gmail.

Haven't really done much on the programming front - other than digging around to find out if I can launch an executable on the client from a web page without the warning pop ups.
Read KB 232077 on MSDN for a solution using cab files.

I'm back...

Havent really been active on the blog - kind of ignored it till now. Anyway, I'm back, fwiw. There's been quite a lot of changes here and I guess that's the thing that's kept me from blogging - add to it the fact that I'm new to maintaining a journal on the web.


These days am looking for some generous person to invite me to Gmail.


Haven't really done much on the programming front - other than digging around to find out if I can launch an executable on the client from a web page without the warning pop ups.

Read KB 232077 on MSDN for a solution using cab files.

Thursday, July 15, 2004

Set up my blog

Just finished setting my place for raves and rants on the net. More to see what a blog provides and out of curiosity rather than anything else.

Set up my blog

Just finished setting my place for raves and rants on the net. More to see what a blog provides and out of curiosity rather than anything else.