Return to Snippet

Revision: 63615
at May 22, 2013 15:03 by sukantahazra


Initial Code
#!/user/bin/perl -w

use strict;
use File::Find;

my @DIRLIST = ("c:\\scratch", "c:\\sukanta\\scratch");

my @table_list;


# Returns the SBRRES_* tables, there can be duplicate tokens
sub get_tables_from_process {
	# read the input file
	open(FILE, $_) or die "Unable to open file $!";
	my @tokens;
	while(<FILE>) {
		push @tokens, split(" ");
	}
	close(FILE);
	map ($_ = uc($_), @tokens);
	@tokens = grep(/\bSBRRES_.*\b/, @tokens);
	return @tokens;
	# find the unique tables
}
	


#
# This function will be called for each file by the find function
#
sub process_file {
	my $fname = $_;
	if (-e $fname && !-d $fname && lc($fname) =~ /.*\.process/) {
		push @table_list, get_tables_from_process($fname);
	}
}
find(\&process_file, @DIRLIST);

my %unique = ();
foreach my $item (@table_list) {
	$unique{$item} ++;
}

@table_list  = sort(keys %unique);

foreach my $item(@table_list) {
	print $item, "\n";
}

Initial URL


Initial Description
This is used to recurse through a directory and perform some action on each file

Initial Title
Recurse through directory and perform action on file

Initial Tags
perl

Initial Language
Perl