Posts

Perl Script to find intersection of lines in two files

#!/usr/bin/perl #/* Author : ~rAGU () */ # /*Descripation: A script to find the intersection set of the lines in two text files */ # /* when one of the file is a subset of the other */ # /* finsec.pl */ # 2004 open(SET, @ARGV[0]); $isInSubset = 0; $count = 0; while ($lineInSet = ) {     chop($lineInSet);     #$lineInSet = ~s / ^ \s * (.* ? )\ s * $ / $1 / ;     $count++;     $counts = 0;     open(SUBSET, @ARGV[1]);     while ($lineInSubset = )     {         $counts++;         chop($lineInSubset);         #$lineInSubset = ~s / ^ \s * (.* ? )\ s * $ / $1 / ;         if ($lineInSet eq $lineInSubset)         {             $isInSubset = 1;    ...

Using Regular Expressions for Program Transformation

I have been investigating the problem of practical code transformation to deal with small changes that have to be made across a large collection of programs in different programming languages . So the problem is not to transform a program entirely but doing small transformations to a large set of programs that too when we have C, Perl, Java etc source programs in that set. This has practical application in software development, code refactoring and testing. A lot of cost savings in software testing is possible if test the suits are well maintained and are automagically transformed using some method. I used a method and published findings on ip.com  which is rather a full system explanation of what I described here in 2011  There are some interesting obstacles to transforming programs. I will try to explain as well as understand some of them through this post. When we want to transform a set of programs in different languages what we are dealing with is a bun...

#Perl recursive file listing in dir with a pattern in name

Modified: use File::Find;    #Recursive file find with a pattern in name    find( sub{               /.*NODE.*\.CAT.*/si && -f $_ and push @bkpfiles, $File::Find::name;               #-d $_ and push @dirs,  $File::Find::name;             }, $dir ); due to: sh1tn

nohup and hist need some care before use

I mean you can not do something like: nohup r prep; something& nohup: cannot run command `hist': No such file or directory Well we could run this provided we eval r something.

rsh2/rsh Permission Denied

Even when everything is set right there could be "Permission Denied" error. .rhosts has all the entries etc. Then check the permission on .rhosts file: chmod 644 on users .rhosts file

Search and replace by parsing nested clause across multilines using recursive regex

 Let me start with the answer. The answer is: perl -p -i -e 'undef $/;$re = qr/\((?:[^()]*|(??{$re}))*\)/;s/(create\s+table \s+.[a-z,A-Z,0-9,.]*\s*$re)\s*(?!SPARSIFY)/$1 SPARSIFY /gis' test/* Now the question and story behind it:  Transforming existing code can be bit tricky and less useful sometimes. But at other times it can literally save our jobs! Here is a typical scenario: FuncName ("Hell brakes $heck if(blah (blah(blah(". "blah(blah))blah)))", Heaven); If the above function is called million times at different places and you want to change that crazy looking nested structure inside a function argument what will you do ? Ok, you can slurp the file to a scalar as in here: http://www.modernperlbooks.com/mt/2009/08/a-one-line-slurp-in-perl-5.html. Then use the recursive regexp idiom: $re = qr/\((?:[^()]*|(??{$re}))*\)/;      $input_scalar =~ s/(Hell\s+brakes\s+.[a-z,A-Z,0-9|.]*\s+if\s*$re)\s*(?!HELLIFY)/$1 HELLIFY /gis; The $re grabs every...

Relational XML

Why use hierarchical data model with relational databases? That is the story of XML in relational databases. Why can't XML be used to define data relations? So I looked around if it existed. This dude has an idea . Then came the boss with lotsa more ideii ! Right on!