Posts

Showing posts from 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

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 everyt