use File::Glob qw( bsd_glob );
# Inputs
my @files = bsd_glob('*');
my $re = qr/^source*/;
my @matching_files;
foreach my $file_name (@files) {
if (!open(my $fh, '<', $file_name)) {
warn("Unable to open file \"$file_name\": $!\n");
next;
}
while (<$fh>) {
if (/$re/) {
push(@matching_files, $file_name);
last;
}
}
}
# Output
print("$_\n")
foreach @matching_files;
####
use File::Glob qw( bsd_glob );
# Inputs
my @files = bsd_glob('*');
my $re = qr/^source*/;
my @matching_lines;
foreach my $file_name (@files) {
if (!open(my $fh, '<', $file_name)) {
warn("Unable to open file \"$file_name\": $!\n");
next;
}
while (<$fh>) {
if (/$re/) {
push(@matching_lines, $_);
}
}
}
# Output
print
foreach @matching_lines;
##
##
use File::Glob qw( bsd_glob );
# Inputs
my @files = bsd_glob('*');
my $re = qr/^source*/;
my @matches;
foreach my $file_name (@files) {
if (!open(my $fh, '<', $file_name)) {
warn("Unable to open file \"$file_name\": $!\n");
next;
}
while (<$fh>) {
if (/$re/) {
# Save the file name, the line number and the line content.
push(@matches, [ $file_name, $., $_ ]);
}
}
}
# Output
print($_->[0], ',', $_->[1], ': ', $_->[2])
foreach @matches;