Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I want to get the file names in a particular directory that aren't soft links. How can I do this?
  • Comment on how do i extract file names that aren't soft links

Replies are listed 'Best First'.
Re: how do i extract file names that aren't soft links
by jdporter (Paladin) on Apr 01, 2004 at 17:29 UTC
    You would use the -l operator to determine whether a file is a symbolic link. For example:
    @non_symlinks = grep { ! -l $_ } @all_files;
    If you are also asking how to get the content listing of the directory...
    my $dirname = 'foo'; opendir D, $dirname or die "read $dirname - $!"; my @visible_files = grep !/^\./, readdir D; closedir D; my @non_symlinks = grep { ! -l "$dirname/$_" } @visible_files;
    The point of the first grep is to filter out all names that start with dot -- including . and ..

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.

      Why do people do the clunky readdir dance when glob() or <*> would do just as nicely in far less space and trouble? In this case, it's even worse, since readdir lists "hidden" files but globbing doesn't.
      my $dirname = 'foo'; my @non_symlinks = grep { not -l } <$dirname/*>;

      --
      [ e d @ h a l l e y . c c ]

Re: how do i extract file names that aren't soft links
by pbeckingham (Parson) on Apr 01, 2004 at 17:31 UTC

    Maybe this?

    my @files = grep {!-l $_} glob '/path/*.html';