Friday, October 7, 2011

#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

Friday, August 12, 2011

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.

Friday, May 20, 2011

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
 
~rAGU

Friday, March 11, 2011

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 everything in the nested brackets (note you can not to this with regular regex). The rest is search replace as usual with some Look-Around and grouping. Depends on what you want to do. I wanted to append a string after the nested clause ended.

You already know the short answer! The long answer is below.

Have fun! 

sub searchReplaceAcrossLines()
{
    my @files =dir/*; # Read all files in a dir
    my $input_scalar; 
    my @input_array; 
    my $holdTerminator = $/; 
    
    # Multiline search. Can use instead: undef $*=1; 
    undef $/;
#Process each file in the dir
foreach $file (@files) { # Process each file

  # Read the file
  open(FILE,"$file") or die;
  @input_array=
  close(FILE);
  $input_scalar=join("",@input_array);
 
#An example
my $re; # A recursive regular expression for everything in brackets
  # Do your substitution here.
    $re = qr/\((?:[^()]*|(??{$re}))*\)/;
    $input_scalar =~ s/(Hell\s+table\s+.[a-z,A-Z,0-9]*\s*$re)\s*(?!READONLY)/$1 READONLY /gis;

  # Write to file
  open(OUTPUT,">$file") or die;
  print(OUTPUT $input_scalar);
  close(OUTPUT);

  print $file . "\n";
} #End for

$/ = $holdTerminator; #Restore
print "Search replace complete \n";
return 0; 
} /end subOne can shorten, optimize etc. But this does what is needed at the moment. dprofpp
Total Elapsed Time = 0.019919 Seconds
  User+System Time = 0.019919 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c  Name
 50.2   0.010  0.010      2   0.0050 0.0050  main::BEGIN
 50.2   0.010  0.010      1   0.0100 0.0099  main::searchReplaceAcrossLines
 0.00   0.000  0.000      1   0.0000 0.0000  File::Glob::GLOB_BRACE
 0.00   0.000  0.000      1   0.0000 0.0000  File::Glob::GLOB_NOMAGIC
 0.00   0.000  0.000      1   0.0000 0.0000  File::Glob::GLOB_QUOTE
 0.00   0.000  0.000      1   0.0000 0.0000  File::Glob::GLOB_TILDE
 0.00   0.000  0.000      1   0.0000 0.0000  File::Glob::GLOB_ALPHASORT
 0.00       - -0.000      1        -      -  DynaLoader::dl_load_file
 0.00       - -0.000      1        -      -  DynaLoader::dl_undef_symbols
 0.00       - -0.000      1        -      -  DynaLoader::dl_find_symbol
 0.00       - -0.000      1        -      -  DynaLoader::dl_install_xsub
 0.00       - -0.000      1        -      -  File::Glob::bootstrap
 0.00       - -0.000      1        -      -  File::Glob::doglob
 0.00       - -0.000      1        -      -  warnings::import
 0.00       - -0.000      1        -      -  warnings::BEGIN
 Here is how profiling works: http://www.perl.com/pub/2004/06/25/profiling.html

Wednesday, August 18, 2010

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!

Saturday, April 3, 2010

C# .NET Application deployment

I am not overly familiar with this stuff. As I try to figure out. Images added to resources should be specified using relative path. If you try Visual Studio is smart enough to suggest.

So the Source filed in the Property tab should like

/YakshaTala;component/Resources/kanlogo.png

YakshaTala is the root folder
 Resources is the sub folder

The rest about deployment soon...
It appears this is a common problem. The solution is here
http://geekrick.blogspot.com/2008/08/frustrating-net-framework-sp1-issue.html
and in many other places.Best way is to google the error message deleting application specific part in the error message. I am able to install my app.

Friday, December 4, 2009

What ailes file systems

File systems have a single region of failure: the table. Corruption of allocation table renders all data waste. Such corruption reduces the problem of finding files in to the known problem of non trivial 'string comparison/search'.

Go write a software to find the file headers in a DVD. We can write one but only if someone can lend a computer that can compute it before I am dead!

So we need an idea that does away single region of failure.