Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep or readdir taking long time

Status
Not open for further replies.

gregaug

Programmer
Sep 9, 2005
61
US
hello,

I have a page that uses a passed in number ($currnum), then checks if any files exist for that number from the specified page. For some reason, the page tends to slow down a lot at the readdir line, and, thru testing, I am positive it is that line. This is chunk of code as it currently stands, but I have had the \Q before the ^, as well as not there at all. Does anyone have any idea on what could be slowing it down so much at this spot? Any help is appreciated.

my $DIR = $ROOT.'temp';
opendir(DR,$DIR);
my $spot='page82.'.$currnum;
@EDITS = grep /^\Q$spot/, readdir DR;
 
You don't need \Q at all from what I can see.

Code:
my $DIR = $ROOT.'temp';
opendir(DR,$DIR) or die "$!";
my $spot= "page82$currnum";
@EDITS = grep /^$spot/, readdir DR;
close DR;

could be there are just a ton of files in the directory?
 
I'm wondering if there are just significantly more in here than elsewhere. Does anyone have any clue how long it takes to grep?
 
I wonder how many times that regex in the grep call is evaulated...

Try this:

@EDITS = grep /^$spot/o, readdir DR;


Mike

I am not inscrutable. [orientalbow]

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top