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.

Signature
Applescript syntax is like English spelling:
Roughly, though not thoroughly, thought through.
Kenny Gatdula - 20 May 2007 18:06 GMT
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";
}
> The Camel book is a bit scary describing performance of filename
> globbing with the <*.pl> or the glob("*.pl") syntax with or without
[quoted text clipped - 52 lines]
> neXt. (10.3.9 here because I need to talk to my SE/30 file
> server.) Oh It's perl 5.8.1-RC3.
Jeremiah Foster - 22 May 2007 13:33 GMT
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
[quoted text clipped - 76 lines]
> >neXt. (10.3.9 here because I need to talk to my SE/30 file
> >server.) Oh It's perl 5.8.1-RC3.
Terence J. Young - 21 May 2007 17:59 GMT
I use something like this (this gets files that match a regex expression
from a folder described in $basefolder)..
sub get_importfiles_from_base_folder {
my ($hashref, %full_pathnames);
$hashref = shift @_;
%full_pathnames = %{$hashref};
opendir(DIR, $base_folder) or croak "Can't open directory
$base_folder $OS_ERROR";
#only add files for types that were not populated thru use of the -f
flag
while (defined(my $file = readdir(DIR))) {
my $my_filename = $file;
if ( not( -T "$base_folder/$my_filename")) {
next;
}
if (($my_filename =~
m/HA_Response_([0-9]{3,3})_[0-9]{8,8}_v[0-9]?[a-z]*.t/)&&(not( defined
($full_pathnames{ "file_$1" }->[2])))) {
$my_filename =~ s/.*\///g;
$my_filename =~ s/^\s//;
$my_filename =~ s/\\ / /g;
if (-e "$base_folder/$my_filename") { #only add valid
files to the %full_pathnames hash
my $hash_key = $my_filename;
$hash_key =~ s/HA_Response_([0-9]{3,3})_.*/file_$1/;
$full_pathnames{ $hash_key }->[0] =
"$base_folder/$my_filename";
$full_pathnames{ $hash_key }->[1] += 1;
}
}
}
close DIR;
return (%full_pathnames);
}
terry
>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.
>
[quoted text clipped - 36 lines]
>
>