in reply to File::Find: Return array of "wanted" files
Use push to add a member to an array. Here is my attempt to implement what you wanted:
#!/usr/bin/perl use strict; use warnings; use File::Find; sub fgrep { my ($regex, $file) = @_; open my $FH, '<', $file or die $!; while (<$FH>) { return 1 if /$regex/; } return 0; } my @found; sub findstuff { my $file = $_; return unless -f $file; my $fullpath = $File::Find::name; if (fgrep(qr/regex/, $file)) { push @found, $fullpath; } } my @dirs = @ARGV; # Populate @dirs. find(\&findstuff, @dirs); print "@found\n";
Update: push added.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: File::Find: Return array of "wanted" files
by alpha-lemming (Novice) on Oct 04, 2013 at 09:52 UTC | |
by Laurent_R (Canon) on Oct 04, 2013 at 17:14 UTC | |
by alpha-lemming (Novice) on Oct 04, 2013 at 19:10 UTC | |
by Laurent_R (Canon) on Oct 04, 2013 at 21:50 UTC | |
by alpha-lemming (Novice) on Oct 07, 2013 at 16:21 UTC | |
|