Although the answer to your question is "use -l", I wonder if instead of just filtering out the symbolic links, you actually want to filter out everything which is not a plain file (e.g. directories, device nodes, named pipes, sockets, etc).

In that case, the test you want is '-f'. See "perldoc -f -f" for more details.

Also, I like to think that the list-processing commands of perl (map, grep) make for very readable (and shorter) code in this sort of situation.

Some other notes:

my $directoryName = '/tmp'; opendir(my $dh, $directoryName) or die "Can't open dir $directoryName : $!"; my @files = grep { -f "$directoryName/$_" } readdir($dh); closedir($dh); print "$_\n" for @files;
The last line (using a one-line for-loop with $_) is a little terse, and I don't often write it that way, but it's a useful trick to know.

Hope you don't mind the extended comment on your post, I thought I'd take the chance to get a few things off my chest :-)


In reply to Re: Using Permissions as a Parameter by jbert
in thread Using Permissions as a Parameter by Dr.Avocado

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.