Find command in your perl script


If you want to search a particular file in a complex directory structure we have Unix command ‘find’ . I have been using this quite a sometime. But, I wanted to incorporate this feature in my perl script – this is bit challenging and didn’t find on any of the sites, don’t know if I missed any important sites.! you can point me if so.

Well , I still could get basic information on this in perl documentation. I am adducing important sites I referred.

http://www.perlmonks.org/?node_id=217166

http://perldoc.perl.org/File/Find.html

Just read about wanted function in the document above and more importantly these variables used.

  • $File::Find::dir is the current directory name,
  • $_ is the current filename within that directory
  • File::Find::name is the complete pathname to the file.

Just tweaked these sample scripts as per my requirement. I am sharing my script here with the explanation inline.

################################

use File::Find;  ## perl module . please use appropriate version of perl software

my $dir=”.”;  ## you can choose your directory

### find command to find .v and .libs in the directory – any search pattern is possible to use ..CHARM..:)
find(\&test_name,$dir);

### Subroutine executed on your each of file/directory parsed by above find command

sub test_name
{
#print $File::Find::name if -f;
#print “$File::Find::name \n”
#if($File::Find::name =~ m/.*\.v$/ ){
if($File::Find::name =~ m/.*\.v$/ | $File::Find::name =~ m/.*\.lib$/)  {
print “$File::Find::name \n” ;  ##prints file name

## prints size of the file in bytes

print $size{$File::Find::name}=-s if -f;
print “\n”;
}
}
Hope it helped .. Enjoy scripting..:) Comment if you are trying out something like this, would love to check it. 🙂

Rajeev Motwani: There wasn’t a startup he didn’t love


Go For It....

Rajeev Motwani, wanted to study mathematics and become another Gauss! His father, however, persuaded him to study computer science. Little did he know how closely the two are related? He graduated with B.Tech. in computer science from IITK in 1983 and PhD from Berkeley in 1988.  Rajeev was a wise theoretician that had the rare knack and desire to turn theory into practical applications. Whenever you use a piece of technology, there is a good chance a little bit of Rajeev Motwani is behind it.

Rajeev played an important role in the founding of Google 15 years ago. He was snatched away from us on June 5, 2009, at the age of 47, in a drowning accident in the backyard swimming pool of his Atherton home after a party celebrating the end of the school year!

Growing up

Rajeev Motwani was born on March 24, 1962 in the Indian city…

View original post 5,646 more words