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 4 of 4 Topic 970 of 1076
Post > Topic >>

Re: globbing with Apple's HFS+

by terry.young@[EMAIL PROTECTED] (Terence J. Young) May 21, 2007 at 11:59 AM

I use something like this (this gets files that match a regex expression 
from a folder described in $basefolder)..

sub get_im****tfiles_from_base_folder {
    my ($hashref, %full_pathnames);
   
    $hashref = ****ft @[EMAIL PROTECTED]
    %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

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.
>
>  
>
 




 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:18:40 CST 2008.