Another perl coding challenge

Todd Rockhold todd.rockhold at ontogen.com
Wed Jan 3 22:29:05 CST 2001


~sdpm~
Thanks for the tips.

Bobby Kleeman suggested:

> Try adding  
> 
> sub rand_str {
> 	my $str = '';
> 	for (my $i = 0; $i < 8; $i++) {
> 		$str .= ('A' .. 'Z', 'a' .. 'z', '_', '0' .. '9')[rand 63];
> 	}
> 	return $str;
> }
> 
> 
> 
> And change this line
> 
> >  	    if (-d $cur && opendir my $dh, $cur)
> 
> To this instead
> 
> my $dh = rand_str;
> if (-d $cur && opendir $dh, $cur)
> 
> 
	[Todd Rockhold]  
	That worked.  602 seconds in my application with the current
directory contents


> If you change the order of these test it will run a little bit faster.  
> Since you already know the name of the file you can test the .wel
> extension quickly and easily (should the test really be /\.wel$/i meaning
> that .wel has to be at the end rather than just somewhere inside there?).
> 
> The open test is taken care of with the -T (-T works by reading the first
> block of the file and seeing if it's contents are in the ascii printable
> range). Try this:
> 
> sub is_well_file # what files do we care about?
> {
> 	return unless $_[0] =~ /\.wel$/i;
> 	return unless -f $_[0] && -T _;
> 	return $_[0];
> }
	[Todd Rockhold]  
	Time was cut from 602 to 214 seconds.




The appropriate modifications of Eugene's tip: 

	use File::Find;
	find({/\.wel$/ && -f $_ && -T _ && -r _ && print}, $DIR);

took 143 seconds to run:


		



~sdpm~

The posting address is: san-diego-pm-list at hfb.pm.org

List requests should be sent to: majordomo at hfb.pm.org

If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:

    unsubscribe san-diego-pm-list

If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.




More information about the San-Diego-pm mailing list