#!/usr/local/bin/perl use Cwd; use threads; use Data::Dumper; my $use_cc = 0; my @dirs = (); if ( $use_cc ) { @dirs = split(/\s+/, $ENV{CLEARCASE_AVOBS}); } else { @dirs = qw(/bin /sbin /usr/local/bin /usr/sfw/bin /usr/bin); } # it's a clearcase thing my $branch = "v4.0.0_gxp_patch"; # hash of dir names with thread values my %threads = (); # hash of dir names with arrays of found items my %Found = (); # large arry to hold all results my @Final = (); foreach my $dir ( sort @dirs ) { chomp($dir); # add dir name to hash $Found{$dir} = (); # create thread and add it to threads hash $threads{$dir} = threads->create({'context' => 'list'}, 'find_thread', $dir, $use_cc, $branch); } foreach my $dir ( sort keys %threads ) { # cycle through threads hash and join up results, put them in hash-of-arrays @{ $Found{$dir} } = $threads{$dir}->join(); } # still all the smaller hash-of-arrays into a large array for easier processing later on foreach my $dir ( sort keys %Found ) { foreach my $item ( sort @{ $Found{$dir} } ) { push(@Final, $item); } } print Dumper(@Final); print "SIZE: " . scalar(@Final) . "\n"; sub find_thread { my $dir = shift; my $cc_flag = shift; my $branch = shift; my @results; chdir $dir or die "Cannot change to $dir\n"; print "Finding all files in dir: $dir\n"; if ( $cc_flag ) { @results = `cleartool find -all -version 'brtype($branch)' -print 2>&1`; } else { @results = `find $dir -print 2>&1`; } return @results; }