in reply to File::Find Questions

Here are two solutions, one using File::Find, and a much shorter one using File::Find::Rule.

Working, tested code:

use File::Find; foreach my $path ( @project_paths ) { if ( my $xml_file = find_first_xml_file( $path ) ) { print "The first XML file under dir '$path' is '$xml_file'\n"; } else { print "No XML files found under dir '$path'\n"; } } sub find_first_xml_file { my ($dir) = @_; # Cannot take multiple dirs. my $file_found; my $wanted = sub { if ( $file_found ) { $File::Find::prune = 1; return; } if ( m{\.xml$}i ) { $file_found = $File::Find::name; $File::Find::prune = 1; } }; find( $wanted, $dir ); return $file_found; }

use File::Find::Rule; foreach my $path ( @project_paths ) { my $rule = File::Find::Rule->file->name('*.xml')->start( $path ); if ( my $xml_file = $rule->match ) { print "The first XML file under dir '$path' is '$xml_file'\n"; } else { print "No XML files found under dir '$path'\n"; } }