Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Is there a better way.

by tokpela (Chaplain)
on Feb 24, 2009 at 09:41 UTC ( #745949=note: print w/replies, xml ) Need Help??

in reply to Is there a better way.

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://745949]
LanX Gesundheit! :)
talexb wonders about dividing developers in those born before the Unix timestamp of zero .. and after. Spoiler: I'm before.
chacham remebers I am a mad scientist
[stevieb]: talexb I'm after by a few years, but we can still be friends because you live in my hometown ;)
[LanX]: White House
[LanX]: next inauguration ?

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2017-08-18 13:29 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (303 votes). Check out past polls.