Just wanted to second Kenny's good advice regarding File::Find. It is a very good tool and will make life a lot easier for you.
Jeremiah Sun, May 20, 2007 at 01:06:35PM -0400: Kenny Gatdula mangled some bits into this alignment: > Hi Doug, > I really couldn't tell you if this is a known problem, but, this > seems to be a job for File::Find. > > Hope this helps, > Kenny > > > use File::Find; > use File::Basename; > > my @directories_to_search = '/Users/kennyg'; > > find(\&wanted, @directories_to_search); > > sub wanted { > my $file = $_; > my $dir = $File::Find::dir; > next unless $file =~ /\.pl/; > my $dirname = basename($dir); > my $filename = fileparse($file,'.pl'); > next unless $filename eq $dirname; > print "Found $file in $dir\n"; > } > > > On May 19, 2007, at 9:15 PM, Doug McNutt wrote: > > >The Camel book is a bit scary describing performance of filename > >globbing with the <*.pl> or the glob("*.pl") syntax with or without > >"use Cwd" in the preamble. Portability is declared questionable. > > > >I find that the only thing that works is <*> within a loop where > >each file is tested by hand. > > > >Consider this bit of doggerel. I'm looking for special cases of a > >*.pl file that appears where * means the short name of the > >enclosing directory. Note especially the "last" command in the > >second while loop. It works not! What happens is that the second > >pass through the while() loop begins in the previous directory at > >the point where it was cut short after finding the file I want. If > >I comment out the last statement, so that all of the files in the > >directory are processed, everything works. > > > >my ($trial, $ddd, $lookfor, $error, $nextdir); > >@thefolders = (); > >@directories = (); > >while ($trial = <*>) > > { > > if (-d $trial) > > { > > push @thefolders, $trial; > ># print REPORT "$trial\n"; > > } > > } > >for $ddd (@thefolders) > > { > > $lookfor = "$ddd.pl"; > > $nextdir = "$mybase/$ddd"; # $mybase, global, is full path to > >initial directory. > > $error = chdir "$nextdir"; > > while (<*>) > > { > > if ($_ eq $lookfor) > > { > > push @directories, $ddd; > ># print REPORT "Added directory $ddd, $lookfor in $ddd\n"; > ># last; # Fails. while() continues where it left off in > >the previous pass > > } > > } > > } > > > >If I try finding <*.pl>, <$lookfor>, or glob("$lookfor") I get a > >real mess with hits from directories that bear no resemblance to > >the most recent chdir which returned without error. > > > >Making the second while loop operate within the while looking for > >directories is even worse. > > > >I'll probably get around to looking more deeply but there's little > >point if someone here knows that it's all a known problem on MacOS > >neXt. (10.3.9 here because I need to talk to my SE/30 file > >server.) Oh It's perl 5.8.1-RC3. > > > >-- > > > >Applescript syntax is like English spelling: > >Roughly, though not thoroughly, thought through. >