I don't see the solution of pulling into an initial @files array scalable.
I would iterate over the directory handle - what if you want to search a directory that has thousands of files (ie lots of memory)?
my $caseNumber = $ARGV[0]; my $pattern = "(.*?)$caseNumber(.*?)"; my $count = 0; my @uploads; ##Open logfiles directory opendir DIR, "Directory" or die "Unable to open Directory, please try +again"; while (my $filename = readdir(DIR)) { if ($filename =~ /$pattern/) { my $filepath = "$directory/$filename"; # make full filepath push(@uploads, $filepath); } } closedir DIR; $count = scalar(@uploads);
Also, I added the directory to the filename since I imagine that you will probably want to access the files at some point from the array.
In reply to Re: Is there a better way.
by tokpela
in thread Is there a better way.
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |