Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Mac > Perl on OSX > Re: globbing wi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 970 of 1076
Post > Topic >>

Re: globbing with Apple's HFS+

by kennyg@[EMAIL PROTECTED] (Kenny Gatdula) May 20, 2007 at 01:06 PM

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 @[EMAIL PROTECTED]
 = '/Users/kennyg';

find(\&wanted, @[EMAIL PROTECTED]
);

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. ****tability 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);
> @[EMAIL PROTECTED]
 = ();
> @[EMAIL PROTECTED]
 = ();
> while ($trial = <*>)
>     {
>     if (-d $trial)
>         {
>         push @[EMAIL PROTECTED]
 $trial;
> #      print RE****T "$trial\n";
>         }
>     }
> for $ddd (@[EMAIL PROTECTED]
)
>     {
>     $lookfor = "$ddd.pl";
>     $nextdir = "$mybase/$ddd";  # $mybase, global, is full path to  
> initial directory.
>     $error = chdir "$nextdir";
>     while (<*>)
>         {
>         if ($_ eq $lookfor)
>             {
>             push @[EMAIL PROTECTED]
 $ddd;
> #          print RE****T "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.
 




 4 Posts in Topic:
globbing with Apple's HFS+
douglist@[EMAIL PROTECTED  2007-05-19 19:15:04 
Re: globbing with Apple's HFS+
kennyg@[EMAIL PROTECTED]   2007-05-20 13:06:35 
Re: globbing with Apple's HFS+
jeremiah@[EMAIL PROTECTED  2007-05-22 14:33:56 
Re: globbing with Apple's HFS+
terry.young@[EMAIL PROTEC  2007-05-21 11:59:01 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Dec 5 0:50:14 CST 2008.