On Jun 18, Pete Emerson said:

>Jeff 'japhy' Pinyan wrote:
>
>> ### ick -- use opendir() and readdir(), or glob()
>
>Okay, sounds good. I'm not quite sure how to use glob. opendir works:
>  opendir(DIR, "$dir");
>  my @ls=readdir(DIR);
>  closedir(DIR);
>
>except I get the directories . and .. , which doesn't cut it for recursion.
>Is there an easy way to parse those out or ignore them?
>Can you give an example of how to do the globbing which also ignores . and ..

You could go over the entries from readdir() one at a time:

  opendir DIR, $dir or die "can't read $dir: $!";

  while (defined(my $file = readdir DIR)) {
    next if $file eq '.' or $file eq '..';
    my $full = "$dir/$file";
    # ...
  }

  closedir DIR;

Similarly for glob().

  while (defined(my $file = glob "$dir/*")) {
    # this automatically any .-file
  }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to