On Apr 8, Ben Crane said:

>I need to get a unique list of directories/sub-dirs,
>etc for certain drives...the problem is, when I run
>the following code, I get loads and loads of
>duplicates, which isn't what I want.

The reason is because you're not printing the entries you find when they
happen to be directories, you're printing the directory OF every entry.

This means that if you have a dir structure like

  /foo/bar/
  /foo/bar/a.txt
  /foo/bar/b.txt
  /foo/bar/c.txt
  /foo/x.txt

will give you the following values printed:

  /foo
  /foo/bar
  /foo/bar
  /foo/bar
  /foo

>sub getlist {
>
>  print DEST "$File::Find::dir\n";
>  print "$File::Find::dir\n";
>}

I would suggest one of these two methods:

  sub getlist {
    print DEST "$File::Find::name\n" if -d;
  }

or else

  {
    my %seen;
    sub getlist {
      return if $seen{$File::Find::dir}++;  # skip if we've already seen it
      print DEST "$File::Find::dir\n";
    }
  }

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN    [Need a programmer?  If you like my work, let me know.]
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to